简体   繁体   中英

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. 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

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],
            })
         }
      }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM