对象字面量可以用作管道参数吗?

Can an object literal be used as a pipe parameter?

我写了一个以对象为参数的管道:

@Pipe({name: "myPipe"})
export class MyPipe implements PipeTransform {
    transform (value: string, options: any): string {
        // do stuff with value and options here
    }
}

当我为 options:

使用变量时它工作正常
<!-- this works fine -->
{{someString | myPipe: someObject}}

但是如果我尝试改用文字:

<!-- this doesn't work -->
{{someString | myPipe: {foo: "bar"}}}

我在控制台中收到一个有趣的重复错误:

ERROR Error: "[object Object]"

我想这是因为对象字面量不能很好地处理插值,但我不确定如何编写它。有没有一种方法可以在不向我的 TypeScript 添加一堆额外变量的情况下完成此操作?

通过this GitHub issue

如果将整个表达式括在括号中,它会起作用:

<!-- this works -->
{{(someString | myPipe: {foo: "bar"})}}

或者如果你在最后两个大括号前加一个space:

<!-- this also works -->
{{someString | myPipe: {foo: "bar"} }}