在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>
原文地址:https://www.cnblogs.com/duwenlei/p/5965240.html