在这里,我需要访问父类的子值。 但我无法得到它。如果我使用指令,它会显示错误。 有人可以帮我在父组件显示孩子的价值观和孩子怎么值可以在反应形式进行验证?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)“>使用反应表单验证??????当我尝试进行验证时发生错误;错误:错误:名称为'模板'的表单控件没有值存取器 –
您能详细说明吗?如果可能的话创建为 –