我想将一个布尔值从一个孩子的状态改变为父母。这是我迄今为止所拥有的。@Output不断变化的布尔状态
子组件
@Input() state: boolean;
@Output() show = new EventEmitter();
@Output() hide = new EventEmitter();
onHover() {
this.state = true;
this.show.emit(this.state);
console.log("state is " + this.state);
}
onHoverOut() {
this.state = false;
this.hide.emit(this.state);
console.log("state is " + this.state);
}
child.html
<a (mouseover)="onHover(show.state)" (mouseleave)="onHoverOut(hide.state)">random Link</a>
父Component
@Component({
selector: 'my-app',
template: '<h3 (show)="toggleState" (hide)="toggleState">toggle state: {{boolshow}}</h3>',
})
export class AppComponent {
toggleState: boolean;
boolshow = this.toggleState;
}
我ñ当我悬停在链接上时,看不到{{boolshow}}。任何帮助都会很棒,谢谢。
没有关系赌注父母和孩子。你甚至不会把'state'变量从父母传递给孩子。 – micronyks
我真的很想理解,而我不是。我认为'(mouseover)=“onHover(show.state)'做到了这一点......然后在h3标签逻辑'(show)=”toggleState“' – Bean0341
中的父组件中选取它。儿童选择器? – yurzui