我用简单的代码测试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