Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>