您好我正在尝试从其子组件访问组件的自定义属性。我得到了未定义的价值。我的组件是......
AppComponent:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: '<star isClicked="false"></star>',
})
export class AppComponent { }
StarComponent:
import { Component,Input} from '@angular/core';
@Component({
selector: 'star',
template: `<i class="glyphicon glyphicon-star-empty"
[class.glyphicon-star]="isClicked"
[class.glyphicon-star-empty]="!isClicked"
on-click="onClick()" >`
})
export class StarComponent {
@Input() isClicked;
constructor(){
console.log(this.isClicked);
}
onClick($event){
this.isClicked = !this.isClicked;
}
}
我从chrome控制台收到undefined
消息。提前谢谢。