简体   繁体   English

未能注入角度分量

[英]Failing to inject an angular component

So what I am trying to do here is make an angular component and get it injected to my angular app. 所以我在这里要做的是制作一个角度组件,并将其注入到我的角度应用程序中。 Here is the code for the angular component: 这是角度分量的代码:

(function(angular) {
'use strict';

angular.module('some.someModule', ['bm.component.templates'])
.directive('somesomeModule', somesomeModule);

somesomeModule.$inject = [];
function somesomeModule() {
    return {
        restrict:'EA',
        templateUrl : 'components/document_preview/document-preview1.html'
    };
}
})(window.angular);

I have an app.js where I inject this new component to app module. 我有一个app.js,我将这个新组件注入到应用程序模块中。

 var someApp = angular.module('some.app', [
    'bm.component.templates',
    'some.hello',
    'some.someModule',
])
.config(config)
.run(run);

I get this from the console: 我从控制台得到的:

在此处输入图片说明 The strange thing is I also have an some.hello angular component with the same sort of code and it is working fine. 奇怪的是,我也有一个具有相同代码种类的some.hello角度组件,并且工作正常。 How to fix this? 如何解决这个问题? Any help would be greatly appreciated. 任何帮助将不胜感激。

You are not declaring your custom module as a dependency of your application module. 您并未将自定义模块声明为应用程序模块的依赖项。

Please try the following : 请尝试以下方法:

 var someApp = angular.module('some.app', [
    'bm.component.templates',
    'some.hello',
    'some.documentPreview',
    'some.someModule'
])
.config(config)
.run(run);

EDIT #1: 编辑#1:

Try wrapping your angular module code in an IFFE as you did with your custom one : 尝试像使用自定义代码一样将角度模块代码包装到IFFE中:

(function (angular) {
    var someApp = angular.module('some.app', [
            'bm.component.templates',
            'some.hello',
            'some.documentPreview',
            'some.someModule'
        ])
        .config(config)
        .run(run);
})(window.angular);

EDIT #2: Here's your code working. 编辑#2: 这是您的代码。

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

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