为什么JS角路线要求你举一个控制器? [英] Why does the Angular JS Route require you to cite a controller?
问题描述
为什么角JS路线要求你举一个控制器?
Coulnd't你刚才举一个观点,然后有view指令链接到控制器?
为什么角JS路线要求你举一个控制器?
块引用>路线做的不可以需要指定一个控制器。如果省略控制器它只会加载指定的页面,但你将有有限的功能。
Coulnd't你刚才举一个观点,然后有view指令链接
到控制器?
块引用>没有。这不是什么指令是。从文档的指令引用的:
什么是指令?
目前高电平,指示是一个DOM元素上的标记(例如一个
属性,元素名称,或CSS类),告诉AngularJS的HTML
编译器($编译)到指定的行为附加到DOM元素
甚至变换的DOM元素和它的孩子。
块引用>...和控制器文档:
了解控制器
在折角,控制器是一个JavaScript
用来充实到角范围构造函数。
当一个控制器通过NG-控制器连接到DOM
指令,角将实例化一个新的控制器对象,使用
指定控制器的构造函数。一个新的子范围将是
可作为注射参数传递给控制器的构造函数
功能$范围。
使用控制器为:
- 设置了
$范围
对象的初始状态。
- 添加行为到
$范围
对象。
块引用>Why does the Angular JS Route require you to cite a controller?
Coulnd't you just cite a view and then have the view directive link to to the controller?
解决方案Why does the Angular JS Route require you to cite a controller?
route does not require a controller to be specified. If you omit the controller it will just load the specified page but you will have limited functionality.
Coulnd't you just cite a view and then have the view directive link to to the controller?
No. This is not what directives are for. Quoting from the docs for directives:
What are Directives?
At a high level, directives are markers on a DOM element (such as an attribute, element name, or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element or even transform the DOM element and its children.
...and the docs for controllers:
Understanding Controllers
In Angular, a Controller is a JavaScript constructor function that is used to augment the Angular Scope.
When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object, using the specified Controller's constructor function. A new child scope will be available as an injectable parameter to the Controller's constructor function as $scope.
Use Controllers to:
- Set up the initial state of the
$scope
object.- Add behavior to the
$scope
object.
这篇关于为什么JS角路线要求你举一个控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!