2017-02-18 50 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,并且它们将被正确评估为字符串。