I'm gonna pass a value into my custom component but it shows me an error in console
Can't bind to 'isFavorite' since it isn't a known native property
here is my code:
favorite.component.ts
import {Component,Input} from 'angular2/core'
@Component ({
selector:'favorite',
template:`
<i class="glyphicon"
[class.glyphicon-star-empty]="!isFavorite"
[class.glyphicon-star]="isFavorite"
(click)="onClick()">
</i>
`
})
export class FavoriteComponent{
@Input() isFavorite = false;
onClick(){
this.isFavorite = !this.isFavorite;
}
}
app.component.ts
import {Component} from 'angular2/core'
import {FavoriteComponent} from './favorite.component'
@Component({
selector: 'my-app',
template: `
<favorite [isFavorite]="true"></favorite>
`,
directives: [FavoriteComponent]
})
export class AppComponent {}
UPDATE: the above code is better way to achieve this functionality and you can fix the problem by passing the name to @input() -> @Input('isFavorite') isFavorite = false;
different way but the same result
i also tried below code but it shows me the same error!
favorite.component.ts
import {Component,Input} from 'angular2/core'
@Component ({
selector:'favorite',
template:`
<i class="glyphicon"
[class.glyphicon-star-empty]="!isFavorite"
[class.glyphicon-star]="isFavorite"
(click)="onClick()">
</i>
`,
inputs: ['isFavorite:is-favorite']
})
export class FavoriteComponent{
@Input('is-favorite') isFavorite = false;
onClick(){
this.isFavorite = !this.isFavorite;
}
}
app.component.ts
import {Component} from 'angular2/core'
import {FavoriteComponent} from './favorite.component'
@Component({
selector: 'my-app',
template: `
<favorite is-favorite="true"></favorite>
`,
directives: [FavoriteComponent]
})
export class AppComponent {}
what's wrong in my code?
inputs: ['isFavorite:is-favorite']?inputs: [...]in the@Component(...)decorator?