【问题标题】:Angular, created a custom pipe that returns a function within a class. Keeps erroringAngular,创建了一个自定义管道,该管道在类中返回一个函数。不断出错
【发布时间】:2020-09-22 20:33:52
【问题描述】:

我有一个创建的类,它在我的 model.ts 文件夹中返回一个函数,如下所示:

@Injectable({
  providedIn: 'root'
})

export class Lookup {
  val: object,
  etc,
  etc,

  getLookupVal(field: string, id: number): string {
    returns stuff..
  }
}

这是我的自定义管道的样子:

import { Pipe, PipeTransform } from '@angular/core';
import { Lookup } from '../config/models';

@Pipe({
  name: 'lookup'
})

export class LookupValuePipe implements PipeTransform {
  constructor(private _lookupValues: Lookup) { }
  transform(field: string, id: number): any {
    return this._lookupValues.getLookupVal(field, id);
  }
}

这是我使用它的一个例子:

<h3>{{'prodstands'| lookup: selectedTask.taskinfo.prodstandid}}</h3>

But for some reason this is the error I keep getting:
ERROR Error: Arguments array must have arguments.
at injectArgs (core.js:685)
at core.js:11183
at _callFactory (core.js:20296)

【问题讨论】:

  • transform(field: string, id: number): any { return this._lookupValues.getLookupVal(field, id); _lookupValues 是什么?
  • @RafaelAndrade 抱歉,我对你的问题感到困惑
  • 我想我现在明白了。 1 秒
  • 从您发布的代码中我可以看出一切正常。也许你在某个地方有一个循环依赖。看起来 Angular 很难注入你的依赖项

标签: html angular pipe


【解决方案1】:

我在这里做了一个例子来连接两个字符串并且工作正常。

https://stackblitz.com/edit/angular-ivy-jl6buq?file=src%2Fapp%2Fhello.component.ts

也许你做错了什么 - 检查这个帖子"Error: Arguments array must have arguments." AppModule

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-12
    相关资源
    最近更新 更多