AngularJS ES6语法中过滤器的未知提供程序错误

时间:2018-03-22 09:49:07

标签: javascript angularjs ecmascript-6 angular-filters

在捆绑和部署到远程服务器后,我在应用中使用过滤器时遇到问题。它在本地工作正常,但如果我远程运行我的应用程序,我会收到错误:

"Error: [$injector:unpr] Unknown provider: eProvider <- e <- filterByQueryFilter"

这是我的代码:

app.js:

import myFilters from "./shared/filters";
import myModule from "./myModule";

export default angular.module('app', [
    lots-of-modules...,
    myFilters,])
    .config(defaultRouting)
    .run(["$http", "$rootScope", "$state", function($http, $rootScope, $state){ //code.. }]);

index.js(在shared / filters文件夹中):

import filterByQuery from "./filterbyquery.filter.js";
import highlightQuery from "./highlightquery.js";
import dateFormatter from "../formatter/dateFormatter";

export default angular.module("my.filters", [])
    .filter("filterByQuery", filterByQuery)
    .filter("highlightQuery", highlightQuery)
    .filter("dateFormatter", dateFormatter)
    .name;

another-module.js(我尝试使用过滤器):

export default class anotherModule{

    constructor() {
        this.restrict = 'E';
        this.replace = false;
        this.template = require('./template.html');

        this.scope = {};

        this.controller = AnotherModule;
        this.controllerAs = 'ctrl';
    }
}

class AnotherModule{
    constructor($scope, $filter) {
        this.$filter = $filter;
    }
}

AnotherModule.$inject = [..., "$filter"];

使用控制器中的过滤器:

res = this.$filter("filterByQuery")(res, this.filterString);

我不确定我在这里做错了,因为它在当地工作正常。此外,highlightQuery过滤器使用template.html

中的管道语法

任何人都知道这里发生了什么?

1 个答案:

答案 0 :(得分:1)

为了执行依赖注入,缩小的AngularJS应用程序应为properly annotated

filterByQuery过滤器工厂功能未注释。由于它包含在单独的文件中,因此使用$inject注释以使其与函数本身保持在同一模块中是有意义的。这是ES6中使用ES模块并由John Papa style guide

提出的优选注释方式
相关问题