[英]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?
Im wanting to create a helper component for laying out bootstrap markup. 我想创建一个用于布局引导标记的助手组件。 Is created a component with the selector: 用选择器创建一个组件:
<bs-input label="Last Name" model="lastname"></bs-input>
the template for this new component looks like this 这个新组件的模板如下所示
<label attr.for="{{model}}">
{{label}}
</label>
<input class="form-control" bind-model="{{model}}" type="text" />
or is could look like this 还是看起来像这样
<label attr.for="__MODEL__">
__MODEL__
</label>
<input class="form-control" ng-model="__MODEL__" type="text" />
but the main thing is I need to manipulate or inherit the meta elements in the template to act as replacements for attributes I set in the parent component either be replacing or somehow passing them through. 但是最主要的是我需要操纵或继承模板中的meta元素,以替换我在父组件中设置的属性(无论是替换还是以某种方式传递)。 The model is where is comes unstuck. 该模型是真正解决问题的地方。
Of course the template parser can't parse non-native elements so I cannot use mg-model or [(ngModel)] in my template 当然,模板解析器无法解析非本地元素,因此我无法在模板中使用mg-model或[(ngModel)]
What is the best way around this? 最好的办法是什么? Can I access the template before it is processed but after the constructor is executed? 我可以在处理模板之前但在构造函数执行之后访问模板吗?
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.