当前位置: 首页 >前端技术 > AngularJS方法 —— angular.bootstrap

AngularJS方法 —— angular.bootstrap

描述:
  此方法用于手动加载angularjs模板
  (官方翻译:注意基于端到端的测试不能使用此功能来引导手动加载,他们必须使用ngapp。 angularjs会检测这个模板是否被浏览器加载或者加载多次并且在控制台给出警告在加载其他模块的时候,这防止了奇怪的结果,在实际应用中,angularjs在尝试其它的多个  实例来研究DOM)。

 

使用方法:

  angular.bootstrap(element, [modules], [config]);

 

参数:

参数名称参数类型描述
elementDOMElementDOM元素
modulesArray要加载的模板
configObject配置选项的对象。

 

返回值:

  返回这个应用程序的新创建的injector 对象。

 

实例:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script src="js/angular.min.js"></script>       
    </head>
    <body>
        <div ng-controller="WelcomeController">
           <span ng-bind="greeting"></span>
        </div>
        <script type="text/javascript">
            var app = angular.module('demo', []).controller('WelcomeController', function ($scope) {
                $scope.greeting = 'Welcome!';
            });
            angular.bootstrap(document, ['demo']);
        </script>
    </body>
</html>

等同于:

 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script src="js/angular.min.js"></script>       
    </head>
    <body ngApp="myApp">
        <div ng-controller="WelcomeController">
           <span ng-bind="greeting"></span>
        </div>
        <script type="text/javascript">
            var app = angular.module('myApp', []).controller('WelcomeController', function ($scope) {
                $scope.greeting = 'Welcome!';
            });
            //angular.bootstrap(document, ['demo']);
        </script>
    </body>
</html>

作者:朱小哥
来源链接:https://www.cnblogs.com/zhuxiaoge/p/6202149.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/front/118433.html

标签:Bootstrap
分享给朋友:

“AngularJS方法 —— angular.bootstrap” 的相关文章

第一个jsp项目 2022年05月14日 10:38:13
一文带你了解React框架 2022年05月16日 21:17:44
模板引擎 Thymeleaf 动态渲染 HTML 2022年06月02日 23:49:44
HTML meta 标签 2022年06月08日 10:36:13
html中如何实现a标签的点击事件 2022年06月09日 21:39:21
html的a标签disabled禁用处理 2022年06月10日 20:16:47
HTML 标签属性列表 2022年06月10日 23:21:55