为什么JS角路线要求你举一个控制器?控制器、路线、JS

由网友(玩家L-)分享简介:为什么角JS路线要求你举一个控制器? Coulnd't你刚才举一个观点,然后有view指令链接到控制器?解决方案   为什么角JS路线要求你举一个控制器?路线做的不可以需要指定一个控制器。如果省略控制器它只会加载指定的页面,但你将有有限的功能。   Coulnd't你刚才举一个观点,然后有view指令链接  到控制器?...

为什么角JS路线要求你举一个控制器?

Coulnd't你刚才举一个观点,然后有view指令链接到控制器?

解决方案   

为什么角JS路线要求你举一个控制器?

路线做的不可以需要指定一个控制器。如果省略控制器它只会加载指定的页面,但你将有有限的功能。

  

Coulnd't你刚才举一个观点,然后有view指令链接  到控制器?

没有。这不是什么指令是。从文档的指令引用的:

  

什么是指令?

    

目前高电平,指示是一个DOM元素上的标记(例如一个  属性,元素名称,或CSS类),告诉AngularJS的HTML  编译器($编译)到指定的行为附加到DOM元素  甚至变换的DOM元素和它的孩子。

...和控制器文档:

  

了解控制器

    设计题 设计A B两台三相交流电动机的控制电路,具体要求是 1 A电动机的控制线路可进行点动和长动控制

在折角,控制器是一个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.

阅读全文

相关推荐

最新文章