ng-style不更新宽度和高度

Sjo*_*Wit 3 javascript css3 angularjs

我正在尝试创建一些自动调整大小的圈子.问题是ng-style属性没有更新样式.http://plnkr.co/edit/3HxSzWIyUsLUW6UwFlRR参见plunker

Javascript:

$scope.sellingPoints = {
    '1':{ 'text':'Newest Technologies'},
    '2':{ 'text':'Rapid Development'},
    '3':{ 'text':'Scaleable Solutions'},
    '4':{ 'text':'Custom CMS'}  
};

$scope.kpi = {};
$scope.sizes = {};
$scope.onResize = function() {
    console.log('joe');
    var kpifit = document.getElementById('fit');
    $scope.sizes.width = kpifit.offsetWidth - 30;
    $scope.kpi.width = $scope.sizes.width + 'px';
    $scope.kpi.height = $scope.sizes.width + 'px';  
    console.log($scope.sizes.width);
} 

angular.element($window).bind('resize', function() {
    $scope.onResize();
})
$timeout(function() {
    $scope.onResize();
}, 300);
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="row no-margin">
    <div class="col-md-3 col-xs-6" id="fit" ng-repeat="item in sellingPoints">
        <div class="kpi" ng-style="{'width':kpi.width,'height':kpi.height}">
            <div class="kpi-text">{{item.text}}</div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

dfs*_*fsq 6

angular.element.prototype.bind(和on)方法绑定的处理程序本身不会触发摘要.所以你需要手动完成:

angular.element($window).bind('resize', function() {
    $scope.onResize();
    $scope.$apply();
});
Run Code Online (Sandbox Code Playgroud)

演示: http ://plnkr.co/edit/dPphd7KkQC7jNqleEgHb?p = info