I am a beginner in Angular JS. I was going through the below link. http://docs.angularjs.org/tutorial/step_00

我是一个角度JS初学者。我正在浏览下面的链接。http://docs.angularjs.org/tutorial/step_00

What are the bootstrap files? Where are they located?

什么是引导文件?它们位于何处?

What is automatic booting and manual initialization of bootstrapping? I read the disadvantage of manual initialization as below.. from the link http://docs.angularjs.org/guide/bootstrap

什么是自动引导和手工初始化引导?下面是手动初始化的缺点。从链接http://docs.angularjs.org/guide/bootstrap

Can anyone explain exactly what is the disadvantage here?

有人能解释一下这里的缺点吗?

6 个解决方案

#1


26

Though Everyone above has answered perfectly and I found what I was looking for but still a working example seem missing.

虽然上面的每个人都回答得很好,我找到了我要找的,但仍然缺少一个有效的例子。

While understanding about Auto / Manual bootstrapping in AngularJS below examples can help a lot :

下面的例子可以帮助您理解AngularJS中的自动/手动引导:

AngularJS : Auto Bootstrapping :

AngularJS:自动引导:

Angular initializes / bootstraps automatically upon DOMContentLoaded event or when the angular.js script is downloaded to the browser and the document.readyState is set to complete. At this point AngularJS looks for the ng-app directive. When the ng-app directive is found then Angular will:

角初始化/引导在DOMContentLoaded事件或当角。js脚本下载到浏览器和文档中。readyState被设置为complete。这时,AngularJS将寻找ng-app指令。当ng-app指令被发现时,角化意志:

  1. Load the module associated with the directive.

    加载与指令相关的模块。

  2. Create the application injector.

    创建应用程序注入器。

  3. Compile the DOM starting from the ng-app root element.

    从ng-app根元素开始编译DOM。

This process is called auto-bootstrapping.

这个过程称为自动引导。

<html>

    <body ng-app="myApp">
        <div ng-controller="Ctrl">Hello {{msg}}!</div>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
        <script>
            var app = angular.module('myApp', []);
            app.controller('Ctrl', function($scope) {
                $scope.msg = 'Nik';
            });
        </script>
    </body>

</html>

JSFiddle : http://jsfiddle.net/nikdtu/ohrjjqws/

JSFiddle:http://jsfiddle.net/nikdtu/ohrjjqws/

AngularJS - Manual Bootstrapping :

AngularJS -手动引导:

You can manually initialized your angular app by using angular.bootstrap() function. This function takes the modules as parameters and should be called within angular.element(document).ready() function. The angular.element(document).ready() function is fired when the DOM is ready for manipulation.

可以使用angular.bootstrap()函数手动初始化角化应用程序。这个函数以模块为参数,应该在angular.element(document).ready()函数中调用。元素(文档).ready()函数在DOM准备好进行操作时被触发。

<html>

    <body>
        <div ng-controller="Ctrl">Hello {{msg}}!</div>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
        <script>
            var app = angular.module('myApp', []);
            app.controller('Ctrl', function($scope) {
                $scope.msg = 'Nik';
            }); 
            //manual bootstrap process 
            angular.element(document).ready(function () { angular.bootstrap(document, ['myApp']); });
        </script>
    </body>

</html>

JSFiddle : http://jsfiddle.net/nikdtu/umcq4wq7/

JSFiddle:http://jsfiddle.net/nikdtu/umcq4wq7/

Note :

注意:

  1. You should not use the ng-app directive when manually bootstrapping your app.

    当手动引导应用程序时,不应该使用ng-app指令。

  2. You should not mix up the automatic and manual way of bootstrapping your app.

    你不应该混淆自动和手动引导应用程序的方式。

  3. Define modules, controller, services etc. before manually bootstrapping your app as defined in above examples.

    在手动引导应用程序之前,定义模块、控制器、服务等。

Reference : http://www.dotnettricks.com/books/angularjs/interview

参考:http://www.dotnettricks.com/books/angularjs/interview

更多相关文章

  1. 如果外部应用程序更改了持久模型(服务器数据库),AngularJS可以自
  2. 在两台服务器上有效地在两个Django应用程序之间进行通信(多租户)
  3. 如何停止Py_Initialise应用程序的崩溃?
  4. 轮询Web服务的最佳方式(例如,对于Twitter应用程序)
  5. 乘客的Django应用程序显示空主页
  6. 用于在Google App Engine上构建应用程序的最佳开源IDE?
  7. 获取Android应用程序的Linux UID
  8. 在Linux中的脚本中安装应用程序
  9. 如何发送一个字节(或字节)来测试在我的应用程序中监听的套接字?

随机推荐

  1. 使用php,ajax和jquery对mysql表进行排序
  2. php调停者模式(mediator pattern)
  3. 在ThinkPhp中实现无限极分类
  4. 用于检查用户名可用性的Javascript帖子无
  5. 管理大量文件的提示?
  6. PHP正则表达式
  7. PHP代码在不需要时在Javascript中自动运
  8. Web2.0 (social media) 企业应用的架构
  9. HTML5关于get请求添加headers的问题
  10. 在页面重新加载时添加活动链接和jquery幻