attr.style在angular2 rc1中不起作用

时间:2016-06-03 11:41:16

标签: javascript angular

我已从Angular2 beta升级到RC1

attr.style工作不正常,没有错误,但这种风格不会出现

<div class="hotspot_info pointer" attr.style="top: {{towerPoint.posY}}%; left: {{towerPoint.posX}}%;" >

3 个答案:

答案 0 :(得分:2)

我会改用ngStyle指令:

<div class="hotspot_info pointer"
   [ngStyle]="{top: towerPoint.posY + '%', left: towerPoint.posX + '%'}" >

答案 1 :(得分:2)

导入:

import {NgStyle} from '@angular/common';

set directive:

directives: [NgStyle]

然后尝试:

<div class="hotspot_info pointer" [ngStyle]="{top: towerPoint.posY+'%'+; left: towerPoint.posX+'%'}" >

答案 2 :(得分:0)

  

ngStyle指令允许您设置CSS样式

<div class="ng-style: expression;"> ... </div>