簡體   English   中英

Angular2-自定義輸入組件的屬性指令

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

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