在AngularJS中同一個頁面配置一個或者多個ng-app


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM