在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>
