2017-02-26 117 views
0

我想就這個問題尋求幫助。我正在研究角2和離子中的動態組件:請檢查下面的情況。Angular2/Ionic 2動態組件屬性

我有分量的名字按鈕組件:

<button-component [label]="I'm a button" **small**></button-component> 

- 必須在按鈕元素進行動態輸入像

內部按鈕組件視圖文件我有:

<button "the single attribute must appear here like small">{{label}}</button> 

輸出將是<button small>I'm a button</button>

我試圖在角2中的所有屬性綁定,但是這是離子性質。

我怎樣才能做到這一點與離子2和角2.通過使用動態單屬性屬性。

在此先感謝。

回答

2

同角2,只需發送一個size屬性,並將其設置爲small

<button-component label="'I'm a button'" size="'small'"></button-component> 

然後在您的按鈕組件:

@Input() size; 

,並在您的模板:

<button [class]="size">{{label}}</button> 

並在CSS中聲明您想要的樣式,例如:

.small { 
... 
} 

.big { 
.. 
} 
+0

會嘗試這一個,謝謝您在./ButtonComponent類ButtonComponent – frogcoder

+0

錯誤 - 致:未能執行的「元素」的setAttribute「:「{{大小}}」不是有效的屬性名稱。 – frogcoder

+0

嘗試更新的代碼 – TheUnreal