我是angularjs中的新成员。我想要做的是在角度应用程序中添加一个简单的控制器。所以,我的代码是像这个 -Angular.JS - 添加控制器时出错
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div ng-app="">
<div ng-init="mySwitch=true">
<p>
<button ng-disabled="mySwitch">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitch"/>Button Disable
</p>
<p>
{{ mySwitch }}
</p>
</div>
</div>
</body>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</html>
所以,它是工作perfectly-
当我ADDD ng-controller="anything"
这样...
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div ng-app="">
<div ng-controller="anything" ng-init="mySwitch=true">
<p>
<button ng-disabled="mySwitch">Click Me!</button>
</p>
<p>
<input type="checkbox" ng-model="mySwitch"/>Button Disable
</p>
<p>
{{ mySwitch }}
</p>
</div>
</div>
</body>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</html>
似乎没有任何工作。
任何人都可以请大家帮忙,我在做什么错?
在此先感谢您的帮助。
看起来像你需要你为什么'ngRoute'在这个依赖定义控制器 – scniro