2 回答

TA貢獻1866條經驗 獲得超5個贊
基本上,您必須將 a 添加*ngIf="showFeedback"
到組件 B 和(click)="showFeedback = !showFeedback"
組件 A 按鈕。
因此,當您單擊按鈕時,將切換 showFeedback 變量(布爾值)。

TA貢獻1906條經驗 獲得超3個贊
@Component({
selector: 'component-a',
styleUrls: ['./app.component.scss'],
template: `
<component-b [showFeedback]="showFeedback"></component-b>
<p (click)="showFeedback=!showFeedback"> Send Feedback </p>
`,
})
export class ComponentA {
showFeedback:boolean=false;
}
@Component({
selector: 'component-a',
styleUrls: ['./app.component.scss'],
template: `
<div *ngIf="showFeedback">Some Baner Component</div>
`,
})
export class ComponentB {
@Input('showFeedback') showFeedback;
}
由于事件處理程序位于 中Component A,Input因此應將 Binding 傳遞Component B給目標元素元素以更改其行為。
[showFeedback]="showFeedback"
@Input('showFeedback') 顯示反饋;
添加回答
舉報