我有1個根組件,有3個子組件,我在其中放置了一些@input來獲得點擊事件,他們稱它們成功地視圖,所以當我點擊根目錄時,我想打開一個子組件(工作正常),但在同一時間,我希望其他兩個人從視圖等消失,但每個人分離(div.hidden的種類)...如果你需要更多的代碼或解釋事先沒有點擊事件hidde 2組件Angular 4
這裏猶豫....感謝是我的根component.html:
<div class="daydetail">
<h1>Detail of day</h1>
<button pButton class="daydetail" type="button" icon="fa-chevron-up" label="Click"(click)="toggleChild()"></button>
<div>
<my-daydetail [showMePartially]="showVar"></my-daydetail>
</div>
</div>
<div class="dailyreport">
<h1>Daily</h1>
<my-dailyreport></my-dailyreport>
</div>
<div class="inventory">
<my-inventory></my-inventory>
</div>
這裏是我的根component.ts:
export class AppliV2Component {
showVar = false;
hideVar = true;
constructor(public userService: UserService) {
}
toggleChild() {
this.showVar = !this.showVar;
this.hideVar = !this.hideVar;
}
}
首先child.html:
<div *ngIf="hideMePartially" class="dailyreport">
<h1>Daily report</h1>
</div> <!-- Fin de dailyreport -->
首先child.ts:
export class MyDailyreportComponent implements OnInit {
@Input() hideMePartially: boolean;
constructor() { }
二child.html:
<div *ngIf="showMePartially" class="daydetail2" > <!-- this part will be toggled by the parent component button -->
<h1>Informations</h1>
</div>
二child.ts:
export class MyInventoryComponent implements OnInit {
@Input() hideMePartially: boolean;
在根component.html代碼,''hideMePartially''不會作爲''input'傳遞給'' my-dailyreport>''。 –
@SameerK謝謝,這是對的我忘了把它放在我的代碼 –