[英]How can I create child elements dynamically and pass properties for them from the parent component In Angular
[英]How do I create an Angular2 Component helper that can pass through items from a parent component and use them as if in the same scope?
我想创建一个用于布局引导标记的助手组件。 用选择器创建一个组件:
<bs-input label="Last Name" model="lastname"></bs-input>
这个新组件的模板如下所示
<label attr.for="{{model}}">
{{label}}
</label>
<input class="form-control" bind-model="{{model}}" type="text" />
还是看起来像这样
<label attr.for="__MODEL__">
__MODEL__
</label>
<input class="form-control" ng-model="__MODEL__" type="text" />
但是最主要的是我需要操纵或继承模板中的meta元素,以替换我在父组件中设置的属性(无论是替换还是以某种方式传递)。 该模型是真正解决问题的地方。
当然,模板解析器无法解析非本地元素,因此我无法在模板中使用mg-model或[(ngModel)]
最好的办法是什么? 我可以在处理模板之前但在构造函数执行之后访问模板吗?
Things Like validation Should be same as in Helpers
just create helper component might be valid.ts
//in the File where You want to use Helper as Example
import {Validator} from "../../../helpers/valid";
@Component({
})
export class Image{
constructor(){
this.Image= fb.group({
ImageTitle: ["1", Validator.required],
})
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.