Javascript 在对象上使用ForEach添加ng样式
我有一个angular中的对象数组,我想做的是迭代数组并添加一个新属性,我可以在ng样式中调用它。如何像这样添加此样式属性Javascript 在对象上使用ForEach添加ng样式,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,我有一个angular中的对象数组,我想做的是迭代数组并添加一个新属性,我可以在ng样式中调用它。如何像这样添加此样式属性 CommentService.GetComments(12535372).then(function () { $scope.comments = CommentService.data(); angular.forEach($scope.comments, function (value, key) { $sco
CommentService.GetComments(12535372).then(function () {
$scope.comments = CommentService.data();
angular.forEach($scope.comments, function (value, key) {
$scope.comments.push('displayPercent:' + 'margin-left:'+ value.percent + '%');
});
});
我的看法是:
<div ng-repeat="comment in comments">
<div style="float: right;" ng-style="comment.displayPercent">
{{ comment.comment }}
</div>
</div>
{{comment.comment}}
假设$scope.comments是一个对象数组:
angular.forEach($scope.comments, function (value, key) {
value.displayPercent = {'margin-left': value.percent + '%'};
});