当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


AngularJS angular.bootstrap()用法及代码示例


AngularJS中的angular.bootstrap()函数是Core ng模块中的函数组件,该模块用于手动启动Angular应用程序,它提供了对应用程序初始化的更多控制。句法:

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

参数值:

  • element:元素是DOM元素(例如文档),它是Angular应用程序的根。
  • Modules:(可选)模块是要加载的模块的数组。
  • Config:(可选)Config是用于配置选项的对象。

范例1:


<html> 
    <head> 
        <title>angular.bootstrap()</title> 
        <script src= 
        "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js">  
        </script> 
        <style> 
        .id { 
        font-size:1.5em; 
        color:green; 
        } 
        </style> 
    </head> 
    <body ng-app="app" style="text-align:Center"> 
        <h1 style="color:green">GeeksforGeeks</h1> 
        <h2>angular.bootstrap()</h2> 
        <div ng-controller="geek"> 
        <span class="id">{{name}}</span>  
        is the computer science portal for geeks. 
        </div> 
        <script> 
            var app = angular.module("app", []); 
            app.controller('geek', ['$scope', function ($scope) { 
                $scope.name = "GeeksforGeeks"; 
            }]); 
            angular.bootstrap(document, ['app']); 
        </script> 
    </body> 
</html>

输出:
bootstrap

范例2:

</div> 
  
<html> 
    <head> 
        <title>angular.bootstrap()</title> 
        <script src= 
        "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js">  
        </script> 
    </head> 
    <body ng-app="app" style="text-align:Center"> 
        <h1 style="color:green">GeeksforGeeks</h1> 
        <h2>angular.bootstrap()</h2> 
        <div ng-controller="geek"> 
            <div class="col-md-3 well" ng-init="count=0"> 
                Male:     
                <input type="radio" ng-model="gender" value="Male" 
                ng-change="layout(gender)" /> 
                Female:   
                <input type="radio" ng-model="gender" value="Female" 
                ng-change="layout(gender)" /> 
                <pre><b>You selected:</b> {{result}} </pre> 
            </div> 
        </div> 
        <script> 
            var app = angular.module("app", []); 
            app.controller('geek', ['$scope', function ($scope) { 
                $scope.layout = function (gender) { 
                    $scope.result = gender; 
                } 
            }]); 
            angular.bootstrap(document, ['app']); 
        </script> 
    </body> 
</html>

输出:
选择之前:
bootstrap
选择后:
bootstrap



相关用法


注:本文由纯净天空筛选整理自Vishal Chaudhary 2大神的英文原创作品 AngularJS | angular.bootstrap() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。