Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Initial/Default value in ng-repeat

未关闭
#185 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
领域
frontend

调研方向

这个 issue 关于 angular-filter 中的 filterBy 和 countBy 过滤器。查看源代码中的过滤器实现,以了解它们如何处理缺失值。用户希望在过滤器找不到匹配项时有一个默认值(例如 0)。先检查这些过滤器的测试套件以了解当前行为,然后修改过滤器逻辑以返回默认 count。通过更新 issue 中的示例来验证:当不再有 'User 1' 值时,将 badge 显示为 0。

由索引模型根据 Issue 内容生成。

描述

My code:

User 1 <span 
class="label label-danger label-as-badge" 
data-ng-repeat="(key,value) in url | filterBy:['ddvalue1']:'User 1' | countBy:'ddvalue1'">{{value}}
</span>

Scenario:
I use combination of filterBy and countBy filter to get drop down value. The default drop down value is set to User 1, its changes when the user selects a value from drop-down and later the value can never be User 1 Example (Default value is User 1 drop-down value is hi,hello,hey. Once user selects either of these values the ddvalue1 field gets updated in DB and user can in future only select value available in drop-down)

The purpose of using the filter above is to display a badge. As the user selects the value from drop down the badge value decrease. Example I have 5 drop-down all set to User 1 initially, hence badge value is 5, once a new drop-down value is selected the the badge value decreases to 4.

The problem is when all the value of drop down is changed the filterBy filter can't find User 1 and as such the count value is not updated. So instead of getting 0 nothing gets displayed. Is there a way to set default values ?

I tried my best to explain, i have attached image as well. I have written same filter for another drop-down, the only thing changes is default value to User 2. As u can see in the image the panel should display value of badges as 1 and 0 for user 1 and user 2 respectively, but since it can't find the filter it displays nothing. I tried using tertiary operator while displaying the output but im not sure what should i compare the *value * too {{ value > 0 ? value : 0}}

upload

主要语言
JavaScript
星标
2.9k
派生
319
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

a8m/angular-filter 的其他 Issue

查看 a8m/angular-filter 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。