[英]Angular2 - Attribute directive for a custom input component
I have a component called <app-craftinput>
. 我有一个名为
<app-craftinput>
的组件。 I'm using this on different layouts. 我在不同的布局上使用它。
The template is: <input type="text" name="" value="" class="input__field input__field--type1">
模板为:
<input type="text" name="" value="" class="input__field input__field--type1">
What is the best method to add attributes like <app-craftinput [value]='23' [label]='Email'></app-craftinput>
in the component's template? 在组件模板中添加诸如
<app-craftinput [value]='23' [label]='Email'></app-craftinput>
类的属性的最佳方法是什么?
Is this what you're looking for? 这是您要找的东西吗?
child .component.ts: 子.component.ts:
import { Input } from '@angular/core';
export class app {
@Input() value:number;
}
parent .component.html: 父.component.html:
<app-craftinput [value]="3"></app-craftinput>
https://angular.io/docs/ts/latest/cookbook/component-communication.html https://angular.io/docs/ts/latest/cookbook/component-communication.html
in order to utilize the information passed from the parent in your child element, in child .component.html: 为了利用子元素.component.html中子元素中从父级传递来的信息:
<label for="{{value}}">{{value}}</label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.