我试图创建一些自动调整大小的圆圈。问题是ng样式属性没有更新样式。 http://plnkr.co/edit/3HxSzWIyUsLUW6UwFlRR看到plunkerng样式不更新宽度和高度
的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);
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>
此代码是否在指令内?或在一个正常的页面?如果它在页面中,我认为你应该按照这个顺序调用controllerName.kpi.width。 –