1

I have the following error appear when I try passing the index of a *ngFor loop through into a component.

Can't bind to 'count' since it isn't a known property of 'app-details'

It seams I can't pass the index through.


First file

import { Component } from '@angular/core';
import { App } from 'reg.interface';

@Component({
  selector: 'reg',
  styleUrls:['reg.component.scss'],
  template:`
    <div class="container">
    <div class="col-6">
      <h2>App Details:</h2>
      <app-details *ngFor="let app of apps; let i = index;"
        [details]="app"
        [count]="i"
      </app-details>
    </div>
  </div>
  `
})

export class RegComponent {
 apps: App[];
}

Second file

import { Component, Input } from '@angular/core';
import { App } from 'reg.interface';

@Component({
  selector: 'app-details',
  template: `
  <div class="col-12">
      <span>Index: {{ details | json }}</span>
      <span>Index: {{ count }}</span>
  </div>
  `
})
export class AppDetailsComponent {
  @Input()
  app: App;
  count: number;
}

reg.interface

export interface App {
  type: string,
  price: number
}

I'm importing the BrowserModule + CommonModule in my main app.module

Any help much appreciated - I can always add more details to the question etc if required. Thanks

2
  • 2
    App-details selector should be app-details and not <app-details></app-details> Commented May 19, 2017 at 9:22
  • Hi, thanks for the note - I've changed that but still get the same error Commented May 19, 2017 at 9:27

1 Answer 1

2
export class AppDetailsComponent {
  @Input() app: App;
  @Input() count: number;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Boom! Nice one! A new input for every input..! Can't believe I missed that one!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.