在我的计划组成部分,我有以下指令,其中selectedPerson是服务的对象和的ShowModal是在规划组件本地布尔参数:Angular2布尔输入参数不工作
<person-popup [person]="planningService.selectedPerson" [show]="showModal"></person-popup>
的PersonPopop组件具有以下简单结构:
import { Component, Input } from '@angular/core';
import { Counselor } from '../entities/counselor';
import { Person } from '../entities/person';
import { Request } from '../entities/request';
@Component({
selector: 'person-popup',
templateUrl: './person-popup.component.html',
styleUrls: ['./person-popup.component.css']
})
export class PersonPopupComponent {
@Input() person: Person;
@Input() show: boolean;
constructor() { }
public displayCss() {
return this.show ? "displayBlock" : "";
}
public toggleShow() {
this.show = !this.show;
console.log("toggleShow: ", this.show)
}
}
相应的HTML视图目前看起来像这样:
<p>{{show}}</p>
<p>{{person?.name}}</p>
<button (click)="toggleShow()">Show</button>
<div class="modal-background {{displayCss()}}" (click)="toggleShow()">
<div class="modal-content animate">
{{person?.name}}
</div>
</div>
当Planning组件启动时,show属性为null
。 selectedPerson的更改始终传播到弹出组件,但showModal参数的值不同。
当showModal
第一次设置为true
在父级中时,它在子组件中设置为true
。
子组件将然后将其本地show
属性设置为false
。 之后,似乎“输入连接丢失”,并且showModal
的所有后续更改不会传播到show
。
有关如何重新设计的建议?
从子[更新父组件属性的可能重复组件在Angular 2](http://stackoverflow.com/questions/41464871/update-parent-component-property-from-child-component-in-angular-2) – n00dl3