gpt4 book ai didi

javascript - Angularjs没有模块错误

转载 作者:行者123 更新时间:2023-12-02 14:12:51 25 4
gpt4 key购买 nike

不确定我的代码有什么问题,我收到错误 angular.min.js:17 Uncaught Error: No module: MyApp

http://jsfiddle.net/9g4nxdar/

(function() {
angular.module("MyApp")
.controller('MyCtrl', myController);

function myController() {
var vm = this;

var item = [{
"name": "James",
"age": 20
}, {
"name": "John",
"age": 20
}]


}
})();

我确实在 View 中声明了这一点 <div ng-app="MyApp">

最佳答案

问题是您刚刚获得了对模块 MyApp 的引用。要创建模块 MyApp,您需要传递一个数组作为第二个参数,如下所示:

app.js

(function(){
// create the module MyApp
angular.module('MyApp', []);

})();

Controller .js

(function() {

// get the reference to MyApp and create the controller
angular.module("MyApp")
.controller('MyCtrl', myController);

function myController() {
var vm = this;

var item = [{
"name": "James",
"age": 20
}, {
"name": "John",
"age": 20
}]

}

})();

来自documentation :

angular.module(name, [requires], [configFn]);

requires - If specified then new module is being created. If unspecified then the module is being retrieved for further configuration.

关于javascript - Angularjs没有模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39354807/

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