AngularJS使用angular.bootstrap完成模組手動載入的方法分析,angularjsbootstrap

來源:互聯網
上載者:User

AngularJS使用angular.bootstrap完成模組手動載入的方法分析,angularjsbootstrap

本文執行個體分析了AngularJS使用angular.bootstrap完成模組手動載入的方法。分享給大家供大家參考,具體如下:

之前我們看到使用ng-app指令,可以實現模組的自動載入。現在我們看下,angular中如何手動載入模組。需要使用到angular.bootstrap這個函數。

<html>  <head>    <script src="angular.js"></script>    <script>    // 建立moudle1    var rootMoudle = angular.module('moudle1', []);    rootMoudle.controller("controller1",function($scope){$scope.name="aty"});    // 建立moudle2    var m2 = angular.module('moudle2', []);    m2.controller("controller2",function($scope){$scope.name="aty"});    // 頁面載入完成後,再載入模組    angular.element(document).ready(function() {      angular.bootstrap(document.getElementById("div1"),["moudle1"]);      angular.bootstrap(document.getElementById("div2"),["moudle2"]);    });  </script>  <head>  <body>    <div id="div1" ng-controller="controller1">div1:{{name}}</div>    <div id="div2" ng-controller="controller2">div2:{{name}}</div>  </body></html>

IE運行這個網頁,發現變數能夠被angular架構正確解析;F12發現控制台也沒有報錯誤。到這裡為止,我們知道了如何載入angular的模組,也明白了手動載入和自動載入的區別。接下來,我們就可以去繼續學習AngularJS架構的其他知識。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.