簡體   English   中英

如何創建一個Angular2 Component助手,該助手可以傳遞父組件中的項目並像在同一作用域中一樣使用它們?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM