Using ng-app without a value

后端 未结 3 1568
时光取名叫无心
时光取名叫无心 2020-11-29 08:59

Usually, you see Angular initialized on a page with a directive like ng-app=\"myModule\", but it is valid to just use ng-app. However, as things l

3条回答
  •  旧巷少年郎
    2020-11-29 09:15

    Read the first example https://docs.angularjs.org/api/ng/directive/ngApp

    In the example below if the ngApp directive were not placed on the html element then the document would not be compiled, the AppController would not be instantiated and the {{ a+b }} would not be resolved to 3.

        
    I can add: {{a}} + {{b}} = {{ a+b }}

    EDIT: You can't(not recommended) register a controller if you don't specify your ng-app. If you just write ng-app or ng-app="", then you'll just get basic angular functions to work, like this stuff: http://www.w3schools.com/angular . So the goal of ng-app is to specify what module you're referring to when registering controllers.

提交回复
热议问题