[英]Adding ng-style using ForEach on Object
I have an array of objects in angular, what I want to do is iterate through the array and add a new property that I can call inside ng-style. 我有一个倾斜的对象数组,我想做的是遍历数组并添加一个新的属性,可以在ng-style中调用。 How can I add this style property like this? 如何添加这样的样式属性?
CommentService.GetComments(12535372).then(function () {
$scope.comments = CommentService.data();
angular.forEach($scope.comments, function (value, key) {
$scope.comments.push('displayPercent:' + 'margin-left:'+ value.percent + '%');
});
});
My View: 我的观点:
<div ng-repeat="comment in comments">
<div style="float: right;" ng-style="comment.displayPercent">
{{ comment.comment }}
</div>
</div>
Assuming $scope.comments is an Array of Objects: 假设$ scope.comments是一个对象数组:
angular.forEach($scope.comments, function (value, key) {
value.displayPercent = {'margin-left': value.percent + '%'};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.