在這裏,我需要訪問父類的子值。 但我無法得到它。如果我使用指令,它會顯示錯誤。 有人可以幫我在父組件顯示孩子的價值觀和孩子怎麼值可以在反應形式進行驗證?angular2需要在父類訪問子值
parent.html:
<browser [template]="coreActivity" (onselect)="onselect($event)" ></browser>
parent.ts:
onselect(select: any)
{
console.log(select.value);
}
child.html:
<md-grid-list cols="3" rowHeight="100px">
<md-grid-tile *ngFor="let core of template" (click)="selectcore(core)">
{{core.value}}
</md-grid-tile>
</md-grid-list>
child.ts:
@Component({
selector: 'template-browser',
templateUrl: './template-browser.component.html',
styleUrls: ['./template-browser.component.css']
})
export class TemplateBrowserComponent implements OnInit {
@Input() template;
@Output() notify: EventEmitter<string> = new EventEmitter<string>();
constructor(private community: CreateCommunityComponent) { }
selectcore(core: any) {
// alert(core.value);
this.notify.emit(core.value);
}
}
嘿謝謝@獨裁者 –
我能夠訪問孩子的價值成parent.How驗證< onselect($ event)「>使用反應表單驗證??????當我嘗試進行驗證時發生錯誤;錯誤:錯誤:名稱爲'模板'的表單控件沒有值存取器 –
您能詳細說明嗎?如果可能的話創建爲 –