简体   繁体   English

Angular:无法实例化模块

[英]Angular: failed to instantiate module

So I am just starting up with Angular and for some reason angular is throwing an error saying my module is unavailable. 所以我刚开始使用Angular,由于某种原因,angular抛出一个错误,说我的模块不可用。

https://docs.angularjs.org/error/ $injector/nomod?p0=plopApp https://docs.angularjs.org/error/ $ injector / nomod?p0 = plopApp

Here is my code so far: (super basic with no real functionality) 到目前为止,这是我的代码:(没有实际功能的超级基础)

@section scripts{
<script src="/Scripts/branding/views.js" type="text/javascript"></script>
}

<h2>Branding Management</h2>
<div ng-app="plopApp">
    <div ng-controller="BrandingController">
        <div></div>
        <div></div>
        <div></div>
    </div>
</div>

Seperate views.js 单独的views.js

(function () {
    var mod = angular.module('plopApp', []);

mod.controller('BrandingController', ['$scope', function ($scope) {
    $scope.greeting = 'Hola!';
}]);
});

Thanks in advance! 提前致谢!

EDIT: I forgot to add that my project does reference the angular libraries 编辑:我忘记添加我的项目确实引用了角度库

You never actually call the function that wraps the call to angular.module . 您永远不会真正调用将调用包装到angular.module的函数。

(function () {
    var mod = angular.module('plopApp', []);

    mod.controller('BrandingController', ['$scope', function ($scope) {
        $scope.greeting = 'Hola!';
    }]);
})() // parentheses call this function

I would also say that this wrapping is unnecessary since you don't need to assign to mod and can also use angular.module('plopApp') to read it, but there is nothing inherently wrong with this style either. 我还要说,这种包装是不必要的,因为您不需要分配给mod ,也可以使用angular.module('plopApp')读取它,但是这种样式也没有内在的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM