简体   繁体   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?

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.

相关问题 如何动态创建子元素并从父组件中为它们传递属性在 Angular - How can I create child elements dynamically and pass properties for them from the parent component In Angular 如何在angular2中将对象从父组件传递到子组件? - How to pass an object from parent component to children components in angular2? 如何在Angular 2中将值从父组件传递给指令? - how can I pass a value from parent component to directive in Angular 2? 如何在Angular中从父级到组件多次传递相同的数据? - How can I pass the same data multiple times from parent to component in Angular? 我可以使用angular2组件中的EventEmitter传递变量吗? - Can I pass variables using EventEmitter from angular2 component? 如何将泛型类型参数传递给Angular2组件? - How can I pass a generic type parameter to an Angular2 component? 如何在angular2中将变量从子组件模板传递到父组件? - How to pass a variable from a child component template to a parent component in angular2? 如何在angular2中的子模块组件中使用父模块组件 - how to use parent module component in child module component in angular2 如何使用依赖注入从angular2中的父组件访问值? - How can i access the values from parent component in angular2 using dependency injection? 如何在Angular 2中将对象从“父”组件传递到“子”组件? - How can I pass the objects from Parent component to the Child component in Angular 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM