Angular:在服务中注入过滤器时出错

时间:2017-04-10 08:21:25

标签: angularjs angular-services angular-filters

export class AlertsService implements IAlertsService {    

    public static $inject = ['$filter'];

    constructor(public $filter: Filters.IHtmlEncodeV2Filter) { 
    }

    public alert(alert: any, type?: string, name: string = "default", callback: any = null, callbackText: string = "default") {
        var test = this.$filter("htmlEncodeV2")(alert);
        var newAlert = new Alert(alert, type, callback, callbackText),
            alerts = this.getNamedAlerts(name);

        while (alerts.length >= this.alertLimit) {
            alerts.splice(0, 1);
        }

        alerts.push(newAlert);
    }
}

上面的代码会注入自定义过滤器HtmlEncodeV2,但每当我运行它时,我总会遇到错误this.$filter is not a function。我错过了什么?我已经遵循了以模块化方式注入对象的惯例。

0 个答案:

没有答案