我这个错误的例子跑不起来,一模一样啊
我这个错误的例子跑不起来,一模一样啊
我这个错误的例子跑不起来,一模一样啊
2015-08-12
可能是因为function调用不了CommonController控制器,这里附上另外一种调用控制器的方式。
<body ng-app="myApp">
<div ng-controller="CommonController">
<button ng-click="commonFn()">common</button>
</div>
<div ng-controller="Controller1">
<p>{{greeting.text}}, Angular.</p>
<button ng-click="control1()">controller1</button>
</div>
<script src="js/Angular.js"></script>
<script src="style.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("CommonController", function($scope){
$scope.commonFn = function(){
alert("common");
};
});
app.controller("Controller1", function($scope){
$scope.greeting = {
text:"Hello"
};
$scope.control1 = function(){
alert("Controller1");
}
});
</script>
</body>
举报