- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ng-app 创建 AngularJS Controller ,但它无法正常工作。
在 Chrome 控制台中,我收到错误 Angular 控制未定义
或不是一个函数未定义
。
ng-app:
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>
Chrome 控制台
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
最佳答案
与 script inlined: jsFiddle 配合使用效果良好,因此脚本加载的时间是可疑的,如上所述。
(顺便说一句。结束语 </form>
看起来不见了:)
关于javascript - AngularJS 错误 - "controller is not defined"或 "not a function got undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27054198/
我是一名优秀的程序员,十分优秀!