Search code examples
angularangular-pipe

Angular - The pipe 'keyvalue' could not be found


I'm testing Angular's keyvalue pipe with simple code:

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" }
}

but it's giving me this error:

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

am i missing anything? Here's my Stackblitz


Solution

  • Your code is fine. You just need to update your dependencies to 6.1 to use keyvalue pipe.

    Stackblitz here