當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。