我正在用ng-app创建一个AngularJS控制器,但它无法正常工作。AngularJS错误 - “控制器未定义”或“未定义函数”
在Chrome控制台中,我收到错误angular ctrl is not defined
或not a function got undefined
。
NG-应用:
var localizationModule = angular.module("localizationModule",[]);
Controller.js
localizationModule.controller('localizationCtrl', ['$scope',
function ($scope) {
$scope.local = {
ProjectSingular: '',
ProjectPlural: '',
ServiceObjectSingular: '',
ServiceObjectPlural: '',
ServicePictureSingular: '',
ServicePicturePlural: '',
}
$scope.Save = function (local) {
console.log(local);
}
}])
HTML
<form ng-app="localizationModule" ng-controller="localizationCtrl">
<div class="panel panel-info">
<div class="panel-heading">
<strong>Localization Setting</strong>
</div>
<div class="panel-body">
<div class="row">
</div>
<div class="row">
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered">
<tr>
<th>Elements</th>
<th>Singular</th>
<th>Plural</th>
</tr>
<tr>
<td>Project</td>
<td><input type="text" required ng-model="local.ProjectSingular" class="form-control" /></td>
<td><input type="text" required ng-model="local.ProjectPlural" class="form-control" /></td>
</tr>
<tr>
<td>Service Object</td>
<td><input type="text" required ng-model="local.ServiceObjectSingular" class="form-control" /></td>
<td><input type="text" required ng-model="local.ServiceObjectPlural" class="form-control" /></td>
</tr>
<tr>
<td>Service Picture</td>
<td><input type="text" required ng-model="local.ServicePictureSingular" class="form-control" /></td>
<td><input type="text" required ng-model="local.ServicePicturePlural" class="form-control" /></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="panel-heading">
<input type="submit" class="btn btn-success pull-right" value="Save" />
<div class="clearfix"></div>
</div>
</div>
</form>
铬控制台
Error: [ng:areq] http://errors.angularjs.org/1.2.17/ng/areq?p0=localizationCtrl&p1=not%20a%20function%2C%20got%20undefined at Error (native) at http://localhost:1914/Scripts/angular.min.js:6:450 at Cb (http://localhost:1914/Scripts/angular.min.js:19:130) at Sa (http://localhost:1914/Scripts/angular.min.js:19:217) at http://localhost:1914/Scripts/angular.min.js:66:451 at http://localhost:1914/Scripts/angular.min.js:53:250 at q (http://localhost:1914/Scripts/angular.min.js:7:386) at N (http://localhost:1914/Scripts/angular.min.js:53:115) at g (http://localhost:1914/Scripts/angular.min.js:47:82) at http://localhost:1914/Scripts/angular.min.js:46:256
两件事情:检查你写脚本标签加载该文件,并尝试对儿童的div移动控制器.. – harishr 2014-11-21 04:44:24
我发现不妥。我测试了角度v1.2.1,所有运行正常。所以角度版本或脚本加载错误有什么问题? – creeper 2014-11-21 04:56:53
我试过两种方法,但问题仍然存在 – 2014-11-21 06:22:34