AngularJS – $watch and unbinding $watch

$watch helps to listen for $scope changes

watch 简单的说,比较像event trigger,用$watch 你可以attched 一个function call在一个$scope的数值上,当这个数值改变的时候,function 就会被active. 例如: 继续阅读: %s

Angular.js 心得总结

最近在学angularJS, 这里是一些学习心得,用来分享:



  • AngularJS in action
  • AngularJS In 60 Minutes by Dan Wahlin (下载链接)

在学习angularJS 之前,你需要知道上面几个方面的知识:

  • Javascirpt
  • MVC

这里是angular开发团队对angularJS MVC 的一个简洁的解释:

The core idea behind MVC is that you have clear separation in your code between managing its data (model), the application logic (controller), and presenting the data to the user (view).

The view gets data from the model to display to the user. When a user interacts with the application by clicking or typing, the controller responds by changing data in the model. Finally, the model notifies the view that a change has occurred so that it can update what it displays.

In Angular applications, the view is the Document Object Model (DOM), the controllers are JavaScript classes, and the model data is stored in object properties.

先从简单的入手,关于angularJS 有几个关键词需要解释。

  • ng-app
    • Tell Angular which part of your page it should expect to manage
  • ng-model
    • Containing data that represents the current state of your application
  • ng-controller
    • Manage the relationship between model and views
  • $scope
    • two way binding object

我觉得理解了上面几个词,基本上就能够入门写一些简单的angularJS了。 继续阅读: %s