[英]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.