Angularjs 中的 controller
接觸過程序開發的小夥伴們對 MVC 的開發方式想必一點也不陌生,是的, angularjs 所採用的方式便是 MVVM 的開發方式,這裏的 controller 即控制器
了解 controller
The ngController directive attaches a controller class to the view. This is a key aspect of how angular supports the principles behind the Model-View-Controller design pattern.
譯文:
ngController 是關註於視圖 controller 的一個指令
指令的基本信息
This directive creates new scope.
This directive executes at priority level 500.
譯文:
指令會創建一個 scope 即作用域
什麽時候使用 controller
當我們須要一個新的模塊而且不希望它跟其它模塊的數據產生沖突的情況下。我們就能夠使用一個 ngController 來獨立這一塊的內容,比方我們的文章正文模塊能夠使用 ng-controller=”AricleController”。而文章中的評論模塊則能夠使用 ng-controller=”CommentController” 來完畢
Angularjs 中的 controller