我正在努力解决如何触发父组件模板中的本地引用,即#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
请添加更多代码。对我来说,它仍然完全不清楚你试图完成什么。 –