Angular Nomod错误,即使模块声明为空数组也是如此 [英] Angular nomod error even when the module declared with empty array
问题描述
尝试创建一个像这样的简单角度应用程序:
Trying to create a simple angular app like this :
HTML
<div ng-app="myApp">
<div ng-controller="appCtrl">
Test Variable :
<input type="radio" class="radio-inline" name="test" ng-model="var.test" value=true> Yes
<input type="radio" class="radio-inline" name="test" ng-model="var.test" value=false> No
<hr>
<p>{{var.test}}</p>
<hr>
<p>Yes: <span ng-if="var.test">$</span></p>
<p>No: <span ng-if="!var.test">$</span></p>
</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.controller('appCtrl', function($scope) {
$scope.var = {
test: true
}
})
但是在页面加载时出现此错误:
But I get this error on page load :
未捕获的错误:[$ injector:modulerr]无法实例化模块myApp由于:错误:[$ injector:nomod]模块'myApp'不是可用的!您可能拼错了模块名称,或者忘记了加载它.如果注册模块,请确保将依赖项指定为第二个参数.
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
这是小提琴.
可能这是一个愚蠢的事情,但是我只是无法弄清楚这段代码出了什么问题,请帮帮我.谢谢!
Possibly it's a silly thing but I just can't figure out what is wrong with this code, please help me out. Thanks!
推荐答案
我也可以通过仅将加载类型更改为不换行"来使您的代码按原样工作:
I could also make your code work as is by just changing the load type to no-wrap in body:
click on javascript tool option and select no wrap- in <body>
https://jsfiddle.net/xgr70bba/3/
这篇关于Angular Nomod错误,即使模块声明为空数组也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!