ng-app 指令用于告诉 AngularJS 应用当前这个元素是根元素,所有 AngularJS 应用都必须要要一个根元素。
使用ng-app来标记一个DOM结点,在网页加载完毕时会自动引导(自动初始化)应用程序。
ng-app可以带属性值,可以指定加载应用模块的名称,ng-app="模块名称"。
但是HTML文档中只允许有一个 ng-app
指令,如果有多个 ng-app
指令,则只有第一个会被使用。
所以想要实现自动加载,那么就不能让ng-app带有属性值,即不能指定载入应用模块名称。
正确写法
{{ 5 + 5 }}
{{ 10 + 10 }}
只加载第一个块
{{ 5 + 5 }}
{{ 10 + 10 }}
以下为ng-app添加属性值的写法都是错误的,会报错
{{ 5 + 5 }}
{{ 10 + 10 }}
{{ 5 + 5 }}
{{ 10 + 10 }}
带属性值时候需要手动加载对应ng-app
{{ 5 + 5 }}{{ 10 + 10 }}
app1会自动加载
app2需要手动加载
angular.bootstrap() ,手动启动 AngularJS
文档地址 https://docs.angularjs.org/api/ng/function/angular.bootstrap
angular.bootstrap(element, [modules], [config]);
Param | Type | Details |
---|---|---|
element | DOMElement | DOM element which is the root of angular application. |
modules (optional) | Array | an array of modules to load into the application.
Each item in the array should be the name of a predefined module or a (DI annotated)
function that will be invoked by the injector as a |
config (optional) | Object | an object for defining configuration options for the application. The following keys are supported:
|
element应该对应根ng-app的id,
modules
模块名数组
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。