首页 > 移动平台 > 详细

在AngularJS中同一个页面配置一个或者多个ng-app

时间:2016-10-15 22:11:54      阅读:189      评论:0      收藏:0      [点我收藏+]

在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

原文:http://www.cnblogs.com/duwenlei/p/5965240.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!