求大神帮我看下代码。怎么解决?
// function CommonController($scope){
// $scope.commonFn=function(){
// alert("这里是通用功能!");
// };
// }
// function Controller1($scope) {
// $scope.greeting = {
// text: 'Hello1'
// };
// $scope.test1=function(){
// alert("test1");
// };
// }
// function Controller2($scope) {
// $scope.greeting = {
// text: 'Hello2'
// };
// $scope.test2=function(){
// alert("test2");
// }
// }
var myModule = angular.module("MyModule", []);
myModule.controller('CommonController',['$scope',function(){
function CommonController($scope){
$scope.commonFn=function(){
alert("这里是通用功能!");
};
}
}])
myModule.controller('Controller1',['$scope',function(){
function Controller1($scope){
$scope.greeting={
text:'hello'
};
$scope.test1=function($scope){
alert('test1')
};
}
}])
myModule.controller('Controller2',['$scope',function(){
function Controller2($scope){
$scope.greeting={
text:'hello'
};
$scope.test2=function($scope){
alert('test2')
};
}
}])注释掉的是原本就有的,可以正常使用,我改写成下面这样,功能就没法实现了
html:
<!doctype html>
<html ng-app='MyModule'>
<head>
<meta charset="utf-8">
</head>
<body>
<div ng-controller="CommonController">
<div ng-controller="Controller1">
<p>{{greeting.text}},Angular</p>
<button ng-click="test1()">test1</button>
<button ng-click="commonFn()">通用</button>
</div>
<div ng-controller="Controller2">
<p>{{greeting.text}},Angular</p>
<button ng-click="test2()">test2</button>
<button ng-click="commonFn()">通用</button>
</div>
</div>
</body>
<script src="js/angular-1.3.0.js"></script>
<script src="MVC3.js"></script>
</html>