【问题标题】:angularjs evaluating scope inside style ie9 not workingangularjs在样式ie9内评估范围不起作用
【发布时间】:2013-09-27 19:04:50
【问题描述】:

所以我基本上有一个带有样式属性的 div 块,在里面我留下了:{{left}}px; right:{{right}}px.
$scope.left 和 $scope.right 得到更新,但不会移动我的项目。
这是一个小提琴

http://jsfiddle.net/climboid/5XqG7/4/

非常感谢任何帮助

<div ng-app ng-controller="Controller" class="container">
  <button class="moveTo" ng-click="findPosClick()"> move to here</button>
  <div class="block" style="left:{{left}}px; top:{{top}}px;"></div>
  <div class="posTxt">left:{{left}}</div>
  <div class="posTxt2">top:{{top}}</div>
</div>

function Controller($scope) {
  $scope.findPosClick = function(){
    var location = event.target ? event.target : event.srcElement;
    var pos = $(location).position();
    $scope.left = pos.left;
    $scope.top = pos.top;
  }

}

另外,当我查看 ie9 控制台时,我没有看到样式属性完全应用于 div...

【问题讨论】:

    标签: css angularjs internet-explorer-9


    【解决方案1】:

    这是 IE 的一个已知问题;它会简单地丢弃它不喜欢的样式标签。

    改用ng-style 指令。

    &lt;div ng-style="{left: left+'px', top: top+'px'}"&gt;&lt;/div&gt;

    【讨论】:

    • 是的,成功了,谢谢安迪!
    【解决方案2】:

    style 属性未解析角度表达式 ({{ }})。因此,您应该在 Angular 应用程序中使用 ng-style 而不是 style

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多