我正在用简单的代码测试 Angular 的 keyvalue
管道:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `<div *ngFor="let prop of testObj | keyvalue">
<div>key: {{prop.key}}</div>
<div>value: {{prop.value}}<div>
</div> `
})
export class AppComponent {
testObj = { id: 1, name: "Abdul Rafay" }
}
但它给了我这个错误:
Template parse errors: The pipe 'keyvalue' could not be found ("]prop of testObj | keyvalue"> key: {{prop.key}} value: {{prop.value}}"): ng:///AppModule/AppComponent.html@0:17 Evaluating src/main.ts Booting application
我错过了什么吗?这是我的 Stackblitz
最佳答案
您的代码没问题。您只需将依赖项更新到 6.1 即可使用 keyvalue
管道。
堆栈 Blitz here
关于Angular - 找不到管道 'keyvalue',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51916111/