AngularJS 学习笔记2

刚学会用Markdown, 现在用这个工具写第二篇博客
接下来主要讨论的内容是三个Angular Directive — ng-app, ng-init,和ng-model。本篇博客主要focus在ng-app。引用W3School的定义

The ng-app Directive

The ng-app directive defines the root element of an AngularJS application.

The ng-app directive will auto-bootstrap (automatically initialize) the application when a web page is loaded.

其中心思想就是这个ng-app定义了一个启动点。打个不太恰当的比喻,它就像是java里面的main()函数。但是区别在于,对于一个app,java里面只允许一个main()函数,但是AngularJS里面允许多个np-app。但第二和第三个ng-app需要手动启动。比如,

<body>
    <div id="app1" ng-app="FirstApp">
        <div ng-controller="MyCtrl">
            <span></span>
        </div>
    </div>
    <div id="app2" ng-app="SecondApp">
        <div ng-controller="MyCtrl">
            <span></span>
        </div>
    </div>
</body>

相对应的手动启动为如下

/**
 * The first App, don't bootstrap it, otherwise will have exceptions.
 * @type {[type]}
 */
var myModule1 = angular.module("FirstApp", []);
...;
// angular.element(document).ready(function() {
//     angular.bootstrap(app1, ['FirstApp']);
// });

/**
 * The second App
 * @type {[type]}
 */
var myModule2 = angular.module("SecondApp", []);
...
angular.element(document).ready(function() {
    angular.bootstrap(app2, ['SecondApp']);
});

在代码块中,我们用…省略了controller的实现部分。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值