標籤:
在AngularJS學習中,對於ng-app初始化一個AngularJS程式屬性的使用需要注意,在一個頁面中AngularJS自動載入第一個ng-app,其他ng-app會忽略,
如果需要載入其他ng-app程式,需要手動添加初始化過程。
手動初始化其他ng-app的javaScript代碼 angular.bootstrap(document.getElementById("id"),[‘id‘]);
<div ng-app="myApp" ng-controller="myCtrl"> <input type="text" ng-model="first"/> <input type="text" ng-model="last"/> <br/> 姓名:{{ first + " " + last}}</div><div id="userForm" ng-app="userForm" ng-controller="userController"> <input type="text" ng-model="username"/><br/> <input type="text" ng-model="password"/><br/> 使用者名稱:{{username}}<br/> 密碼: {{password}}</div>
<script type="text/javascript"> var app = angular.module("myApp",[]); app.controller("myCtrl",function($scope){ $scope.first = "test"; $scope.last = "test"; }); var userApp = angular.module("userForm",[]); userApp.controller("userController",function($scope){ $scope.username = "test"; $scope.password = "test"; }); angular.bootstrap(document.getElementById("userForm"),[‘userForm‘]);</script>
在AngularJS中同一個頁面配置一個或者多個ng-app