2017-02-18 17 views
0

正在使用angular2 This modal和我想的模式彈出位置向左這是香港專業教育學院試圖Angular2模式彈出定位留下

<modal #categoriesmodal [cssClass]="modalchecklist"> 
    <modal-header [show-close]="true"> 
    <h4 class="modal-title">I'm a modal!</h4> 
    </modal-header> 
    <modal-body> 
    Hello World! 
    </modal-body> 
    <modal-footer [show-default-buttons]="true"></modal-footer> 
</modal> 

在CSS類

.modalchecklist{ 
    position:absolute; 
    top:0; 
left:0 

}

我曾嘗試在css類中添加//background color:red,但這樣做會失敗,並將css添加到背景文檔中,而不是模型

我要去哪裏錯了CSS類

伊夫還檢查Chrome開發人員工具,但他們太不解決問題。

可能是自己做錯了什麼

+0

您是否嘗試了沒有括號?像這樣:'

+0

它仍然失敗,我嘗試用類而不是cssClass,但現在模態位於左角而不是右角 –

回答

1

要Angular2應用樣式屬性,你可以使用[style]指令,這樣

<what-ever [style.backgroundColor]="'red'">I am red</what-ever> 

要應用類,使用ngClass

<what-ever [ngClass]="'first'"><what-ever> 
<what-ever [ngClass]="['first', 'second']"></what-ever> 
<what-ever [ngClass]="{'first':true, 'second':conditionExp}"><what-ever> 

有關多個語法選項和使用表達式,請參見上面的ngClass鏈接。

請注意,所有這些方法都是指令,並且直接綁定到範圍,他們期望表達式。爲了傳遞字符串,您需要將您的表達限定爲字符串:使用單引號 s內部雙引號 s,並且它們將被正確評估爲字符串。