[英]Angular2 - Attribute directive for a custom input component
我有一個名為<app-craftinput>
的組件。 我在不同的布局上使用它。
模板為: <input type="text" name="" value="" class="input__field input__field--type1">
在組件模板中添加諸如<app-craftinput [value]='23' [label]='Email'></app-craftinput>
類的屬性的最佳方法是什么?
這是您要找的東西嗎?
子.component.ts:
import { Input } from '@angular/core';
export class app {
@Input() value:number;
}
父.component.html:
<app-craftinput [value]="3"></app-craftinput>
https://angular.io/docs/ts/latest/cookbook/component-communication.html
為了利用子元素.component.html中子元素中從父級傳遞來的信息:
<label for="{{value}}">{{value}}</label>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.