运行以下示例时,我收到AngularJS错误的参数错误,请让我知道我在哪里做错了?实际上,如果我在外面/正常运行,下面的代码工作正常,但是当我在我的应用程序中复制/粘贴此代码时,它会给出以下错误。 (这个页面/标签显示在我的应用程序的控制器中,如:TestController,可以在coffeescript中找到。但是我不需要任何coffeescript来满足这个要求,我需要它在AngularJs中。所以,在这个标签中,我需要显示下面的代码/按钮。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
var myApp = angular.module('myApplication', []);
myApp.controller('TestController', ['$scope', function($scope){
$scope.test = function(){
alert("Success");
}
}]);
</script>
</head>
<body>
<div ng-app="myApplication">
<div ng-controller="TestController">
<div class="tab-pane" id="wizards">
<button type="button" ng-click="test();">Test</button>
</div></div></div>
</body>
</html>
错误:Error: [ng:areq] http://errors.angularjs.org/1.4.8/ng/areq?p0=TestController&p1=not%20a%20function%2C%20got%20undefined
答案 0 :(得分:2)
这Plunker对我有用
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"> </script>
<script src="script.js"></script>
</head>
<body>
<div ng-app="myApplication">
<div ng-controller="WizardController">
<button ng-click="test()">Test</button>
</div>
</div>
</body>