Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Elise St Hilaire
Elise St Hilaire
13,358 Points

Angular2 Error: Cannot find a differ supporting object '[object Object]' of type 'object'

I get this error when trying to use a pipe to filter through runners. I'm guessing it has to do with how I subscribed to observables when grabbing the runners from the database.

This is my code in the component where the runners array is defined:

javascript
  ngOnInit() {
    this.runnerService.getRunners().subscribe(dataLastEmittedFromObserver => {
      this.runners = dataLastEmittedFromObserver;

      let thisComponent = this;
      this.runners.forEach((runner) => {
        runner = new Runner(
          runner.name,
          runner.role,
          runner.profilePic
        )
      });
    })

This is where I create the pipe:

javascript
  transform(value: any, runnerRole) {
    var filteredRunners= this.af.database.list('runners',{
      query:{
        orderByChild: 'role',
        equalTo: runnerRole
      }
    });
    return filteredRunners;
  }

And this is where I use it in the HTML:

html
<div *ngFor="let runner of runners | role: Leader" class="panel panel-default">

  <div class="panel-body">
    <h3 (click)="goToDetailsPage(runner)">{{runner?.name}}</h3>
    <div *ngIf="currentRoute==='/admin'">
      <app-edit-runner [selectedRunner]="runner"></app-edit-runner>
    </div>
  </div>
</div>