gpt4 book ai didi

javascript - AngularJS 错误 - "controller is not defined"或 "not a function got undefined"

转载 作者:行者123 更新时间:2023-11-28 07:49:15 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com