国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

AngularJS 在同一個界面啟動多個ng-app應用模塊詳解

2019-11-19 18:23:01
字體:
來源:轉載
供稿:網友

AngularJS默認在一個html界面中只啟動一個

 ng-app 模塊,而且是界面中第一次出現的那個使用 ng-app 聲明的模塊,該問題可以通過查看AngularJS源代碼或者是文檔驗證。

解決方案:

直接上代碼,如果有興趣了解其中緣由,可以選擇閱讀后面的部分;

<!DOCTYPE html><html><head lang="zh_CN"> <meta charset="UTF-8"> <title>AngularJS Source Code Analysis</title> <script src="source/angular.min.js" type="text/javascript"></script> <script src="source/angular-route.min.js" type="text/javascript"></script></head><body> <div ng-app="myApp-0" ng-controller="nameCtrl"> <input type="text" ng-model="age"/>{{ demo }}--{{ age }} <ul>  <li ng-repeat="val in names" ng-bind="val"></li> </ul> </div> <!-- 并行啟動多個ng-app --> <div id="test-0" ng-controller="testCtrl_0"> <p>{{content.message}}</p> </div> <div id="test-1" ng-controller="testCtrl_1"> <p>{{content.message}}</p> </div></body><script> var myApp_0 = angular.module("myApp-0", []); myApp_0.controller('nameCtrl', function ($scope, $rootScope){ $scope.names = ["shen", "amy", "sereno"]; $scope.age = 24; $rootScope.demo = "demo"; }); var myApp_1 = angular.module("myApp-1", []); myApp_1.controller('nameCtrl-1', function ($scope, $rootScope){ $scope.names = ["shen-1", "amy-1", "sereno-1"]; $rootScope.age = 24; }); // 并行啟動多個 ng-app var myApp1mod = angular.module('test-0',[]); myApp1mod.controller('testCtrl_0',function($scope){ var content= {}; content.message = "Hello Test-0"; $scope.content= content; }); var myApp2mod = angular.module('test-1',[]); myApp2mod.controller('testCtrl_1',function($scope){ var content= {}; content.message = "Hello Test-1"; $scope.content= content; }); angular.element(document).ready(  function (){  angular.bootstrap(document.getElementById("test-0"), ["test-0"]);  angular.bootstrap(document.getElementById("test-1"), ["test-1"]);  } );</script></html>

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐亭县| 河南省| 济阳县| 满洲里市| 齐河县| 绵竹市| 永福县| 麻城市| 丰台区| 漳州市| 乳山市| 平原县| 通州市| 鄂州市| 友谊县| 铜陵市| 汉沽区| 遂宁市| 三河市| 琼海市| 镇原县| 宁波市| 资源县| 思南县| 绥德县| 承德县| 石楼县| 长岛县| 平定县| 大荔县| 临泽县| 清涧县| 肥西县| 紫阳县| 海宁市| 永寿县| 大石桥市| 峨眉山市| 聂拉木县| 崇州市| 邮箱|