Why am I getting 'Error: $injector:modulerr Module Error' in this basic Controller?
Why am I getting 'Error: $injector:modulerr Module Error' in this basic Controller?
jsFiddle: http://jsfiddle.net/leongaban/2g8vwmzo/
Failed to instantiate module myApp due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.3.15/$injector/nomod?p0=myApp
at Error (native)
at https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js:6:417
at
(function() {
'use strict';
var app = angular
.module('myApp', ['MyCtrl'])
.controller('MyCtrl', Controller);
Controller.$inject = ['$scope'];
function Controller($scope) {
var vm = this;
var vs = $scope;
activate();
////////////////////////////////////////////////////////////////
function activate() {
vs.name = "Whosebug";
vs.fonts = [
{title: "Arial" , text: 'Arial rules!' },
{title: "Helvetica" , text: 'Helvetica is hot!' }
];
vs.change= function(option){
alert(option.title);
}
}
}
})();
标记:
<div ng-app="myApp" ng-controller="MyCtrl">
<h1>{{name}}</h1>
<select ng-model="opt"
ng-change="change(font)">
<option ng-repeat="font in fonts" value="{{font.title}}">
{{font.title}}
</option>
</select>
<p>{{opt}}</p>
</div>
改变这个
.module('myApp', ['MyCtrl'])
到
.module('myApp', [])
一切顺利!
module函数的第二个参数是一个模块依赖数组,即myApp
模块所依赖的其他模块。 MyCtrl
是控制器而不是模块。
更新:更改fiddle设置。将第二个下拉菜单设置为 no wrap in body
在此处查看 运行 http://jsfiddle.net/0h4cs2tp/
jsFiddle: http://jsfiddle.net/leongaban/2g8vwmzo/
Failed to instantiate module myApp due to: Error: [$injector:nomod] http://errors.angularjs.org/1.3.15/$injector/nomod?p0=myApp at Error (native) at https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js:6:417 at
(function() {
'use strict';
var app = angular
.module('myApp', ['MyCtrl'])
.controller('MyCtrl', Controller);
Controller.$inject = ['$scope'];
function Controller($scope) {
var vm = this;
var vs = $scope;
activate();
////////////////////////////////////////////////////////////////
function activate() {
vs.name = "Whosebug";
vs.fonts = [
{title: "Arial" , text: 'Arial rules!' },
{title: "Helvetica" , text: 'Helvetica is hot!' }
];
vs.change= function(option){
alert(option.title);
}
}
}
})();
标记:
<div ng-app="myApp" ng-controller="MyCtrl">
<h1>{{name}}</h1>
<select ng-model="opt"
ng-change="change(font)">
<option ng-repeat="font in fonts" value="{{font.title}}">
{{font.title}}
</option>
</select>
<p>{{opt}}</p>
</div>
改变这个
.module('myApp', ['MyCtrl'])
到
.module('myApp', [])
一切顺利!
module函数的第二个参数是一个模块依赖数组,即myApp
模块所依赖的其他模块。 MyCtrl
是控制器而不是模块。
更新:更改fiddle设置。将第二个下拉菜单设置为 no wrap in body
在此处查看 运行 http://jsfiddle.net/0h4cs2tp/