您的位置:首页 > 移动开发

angular在一个页面中使用两个ng-app的方法(二)

2017-02-20 14:54 771 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ng-app指令,angular找到第一个ng-app就不会再找了,在一个页面中只使用一个ng-app.</title>
</head>
<body ng-app="myApp">

<input type="button" ng-controller="App1Controller" ng-click="do1()" value="按钮1" />
<input type="button" ng-controller="App2Controller" ng-click="do2()" value="按钮2">

<script src="bower_components/angular/angular.js"></script>

<script>

var myApp1 = angular.module('myApp1', []);
myApp1.controller('App1Controller', ['$scope', function($scope){
$scope.do1 = function(){
console.log(11111);
};
}]);

var myApp2 = angular.module('myApp2', []);
myApp2.controller('App2Controller', ['$scope', function($scope){
$scope.do2 = function(){
console.log(22222);
};
}]);

/**
* myApp Mod'myApp1','myApp2'ul;
*
* Description
*/
angular.module('myApp', ['myApp1','myApp2']);
</script>
</body>
</html>


就是用一个大的模块将两个小模块包起来
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐