Do you have to us ng-Controller in the view or can you just declare it in the $routeProvider?

后端 未结 3 1562
一整个雨季
一整个雨季 2021-01-14 12:19

I recently realized I had not used ng-Controller to declare the official scope of my controller in the HTML but had only mentioned it in $routeProvider and all APPEARS to be

3条回答
  •  暖寄归人
    2021-01-14 12:58

    You should only declare the controller in your $routeProvider. Otherwise, it will be instanciated twice.

    In some case it would be transparent but it can easily lead to bugous behaviour.

    As a reference, the Angular guide provides code samples about how do use ng-view: https://docs.angularjs.org/api/ngRoute/directive/ngView

提交回复
热议问题