Angular2 forms angular2需要访问父类中的子值
这里,我需要访问父类中的子值。 但是我不能得到它。如果我使用指令,它会显示错误。 是否有人可以帮助我在父组件中显示子值,以及如何以反应形式验证子值 parent.html:Angular2 forms angular2需要访问父类中的子值,angular2-forms,Angular2 Forms,这里,我需要访问父类中的子值。 但是我不能得到它。如果我使用指令,它会显示错误。 是否有人可以帮助我在父组件中显示子值,以及如何以反应形式验证子值 parent.html: <browser [template]="coreActivity" (onselect)="onselect($event)" ></browser> child.html: <md-grid-list cols="3" rowHeight="100px"> <md-g
<browser [template]="coreActivity" (onselect)="onselect($event)" ></browser>
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>
{{core.value}
child.ts:
onselect(select: any)
{
console.log(select.value);
}
@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);
}
}
onSelect(select)
{
console.log(select.value);
}
@组件({
选择器:“模板浏览器”,
templateUrl:'./模板浏览器.component.html',
样式URL:['./模板浏览器.component.css']
})
导出类TemplateBrowserComponent实现OnInit{
@输入()模板;
@Output()notify:EventEmitter=neweventemitter();
构造函数(私有社区:CreateCommunityComponent){}
选择核心(核心:任何){
//警报(核心值);
this.notify.emit(core.value);
}
}
为了访问父级中的child.html
,您需要创建另一个组件,并将该组件名称用作父级中的标记。
类似组件的名称是“child”
将
保留在parent中为了访问parent中的child.html
,您需要创建另一个组件,并将该组件名称用作parent中的标记。
类似组件的名称是“child”
在通过
EventEmitter
传递值时,将
保留在parent中,您需要在parent.html
中随子组件声明一起传递它
<browser (notify)="onSelect($event)" [template]="coreActivity" (onselect)="onselect($event)" ></browser>
在通过
EventEmitter
传递值时,需要在parent.html
中随子组件声明一起传递
<browser (notify)="onSelect($event)" [template]="coreActivity" (onselect)="onselect($event)" ></browser>
你好,你能提供更多细节吗?可能的代码以及你好,你能提供更多的细节吗?可能的代码我也可以访问父项中的子值。如何使用react form validation进行验证??????当我尝试进行验证时,它给出了错误;错误:名为“template”的表单控件没有值访问器。您能详细说明一下吗?如果可能的话,为它创建一个新的线程。你能研究一下吗:我可以访问父线程中的子线程值。如何使用react表单验证进行验证??????当我尝试进行验证时,它给出了错误;错误:名为“template”的表单控件没有值访问器。您能详细说明一下吗?如果可能,为此创建新线程。请查看: