我正在努力解決如何觸發父組件模板中的本地引用,即#rightNav
從子組件模板單擊事件(click)="rightNav.open()"
使用Material 2 sidenav。我想我需要使用@ViewChild
註釋,但不知道如何。如何從Angular 2中的子組件事件觸發父組件中的本地引用?
子組件模板(應用條件列表):
<div *ngFor="let condition of conditions" [class.selected]="condition === selectedCondition"
(click)="rightNav.open()"></div>
父組件模板(條件部分):
import { Component} from '@angular/core';
import { ConditionsListComponent } from './listComponent/conditions-list.component';
@Component({
moduleId: module.id,
selector: 'app-conditions',
template: `
<md-sidenav #rightNav align="end" mode="side">
"Condition details will open here on click event"
</md-sidenav>
<app-conditions-list></app-conditions-list>`,
styleUrls: ['./conditions.component.css'],
directives: [
ConditionsListComponent,
]
})
export class ConditionsComponent {
title = "Conditions Manager"
}
子組件嵌套在父組件模板。 謝謝!
對我來說,目前尚不清楚''和''是相關的。 「父母成分」是什麼意思? –
謝謝@GünterZöchbauer。我清理了代碼以刪除不相關的代碼。父組件是#rightNav引用所在的位置。 – odenman250
請添加更多代碼。對我來說,它仍然完全不清楚你試圖完成什麼。 –