gpt4 book ai didi

javascript - angularjs 避免 ngrepeat 中的空字段

转载 作者:行者123 更新时间:2023-12-03 11:17:25 25 4
gpt4 key购买 nike

删除|后该功能似乎没问题货币:“£” 过滤器。是否有任何选项可以仅显示当前用户数量?

(function() {
var app = angular.module('myApp', []);
app.controller('roomController', function($scope) {
$scope.users = [{
id: 1,
firstname: 'member',
spent: 206.98
}, {
id: 2,
firstname: 'member',
spent: 12.23
}, {
id: 3,
firstname: 'member',
spent: 302.12
}, {
id: 4,
firstname: 'member',
spent: 198.21
}, {
id: 5,
firstname: 'member',
spent: 85.85
}];
$scope.currentuser = 4;
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="roomController">
<h2 ng-repeat="user in users"><i class="fa fa-gbp"></i> {{ user.id === currentuser ? user.spent: '' | currency:"£"}}</h2>
</div>
</div>

最佳答案

如果我理解正确的话,你不需要三元运算符,而是输入 ng-if<h2>这正在重复。

见下文:

(function() {
var app = angular.module('myApp', []);
app.controller('roomController', function($scope) {
$scope.users = [{
id: 1,
firstname: 'member',
spent: 206.98
}, {
id: 2,
firstname: 'member',
spent: 12.23
}, {
id: 3,
firstname: 'member',
spent: 302.12
}, {
id: 4,
firstname: 'member',
spent: 198.21
}, {
id: 5,
firstname: 'member',
spent: 85.85
}];
$scope.currentuser = 4;
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="roomController">
<h2 ng-repeat="user in users" ng-if="user.id === currentuser"><i class="fa fa-gbp"></i> {{ user.spent | currency:"£"}}</h2>
</div>
</div>

关于javascript - angularjs 避免 ngrepeat 中的空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27278835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com