Placement of the ng-app directive (html vs body)

前端 未结 3 1118
北海茫月
北海茫月 2020-12-04 08:05

I recently reviewed the code for a webapp built with angular and found that it was written with the ng-app=\"myModule\" directive placed on the

3条回答
  •  醉梦人生
    2020-12-04 08:54

    AngularJS will bootstrap the first ng-app it finds! That's it. If you have more than one ng-app, it will only process the first one. If you want to bootstrap any other element use angular.bootstrap()

    The value of the ng-app attribute is a module that have been created using:

    angular.module("module_name", [])
    

    A module defines how angular will bootstrapped because we do not have a main() method unlike other programming languages. If ng-app's value is empty, then it defaults to use 'ng', the default module.

    It was said to be slightly faster because angular will process all of the elements inside the element where ng-app was. But I doubt slightly part because the difference will be hardly noticeable at all, unless you have a very very bulky DOM.

    If you want examples here: http://noypi-linux.blogspot.com/2014/07/angularjs-tutorials-understanding.html

提交回复
热议问题