Skip to content

fix(module:input-number): ngModel value can be undefined#9269

Merged
HyperLife1119 merged 5 commits into
NG-ZORRO:masterfrom
dev-anton-ko:master
Jul 10, 2025
Merged

fix(module:input-number): ngModel value can be undefined#9269
HyperLife1119 merged 5 commits into
NG-ZORRO:masterfrom
dev-anton-ko:master

Conversation

@dev-anton-ko

@dev-anton-ko dev-anton-ko commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Application (the showcase website) / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Binding of the undefined field cause the error in the log:

core.mjs:6537 ERROR TypeError: Cannot read properties of undefined (reading 'toString') at defaultFormater (ng-zorro-antd-input-number.mjs:313:18) at _NzInputNumberComponent.setValue (ng-zorro-antd-input-number.mjs:468:49) at ng-zorro-antd-input-number.mjs:418:12 at untracked (untracked-BKcld_ew.mjs:573:12) at untracked2 (core.mjs:38350:10) at _NzInputNumberComponent.writeValue (ng-zorro-antd-input-number.mjs:416:5) at onChange (forms.mjs:3476:23) at forms.mjs:3992:42 at Array.forEach (<anonymous>) at FormControl2.setValue (forms.mjs:3992:22)

Issue Number: N/A

What is the new behavior?

No error message.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Just bug has been fixed.
The discussion had been created early #9121
I am not sure that number | null is a proper type for value of this component.

@dev-anton-ko dev-anton-ko requested a review from vthinkxie as a code owner July 2, 2025 15:25
@zorro-bot

zorro-bot Bot commented Jul 2, 2025

Copy link
Copy Markdown

This preview will be available after the AzureCI is passed.

@codecov

codecov Bot commented Jul 2, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.11%. Comparing base (2c7c402) to head (f95ca49).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9269   +/-   ##
=======================================
  Coverage   92.11%   92.11%           
=======================================
  Files         561      561           
  Lines       19609    19610    +1     
  Branches     3101     3102    +1     
=======================================
+ Hits        18062    18063    +1     
  Misses       1207     1207           
  Partials      340      340           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread components/input-number/input-number.component.ts Outdated
@HyperLife1119

Copy link
Copy Markdown
Collaborator

I think we just need to convert undefined to null in writeValue.

  writeValue(value: number | null | undefined): void {
    if (isNil(value)) value = null;
    untracked(() => {
      this.value.set(value);
      this.setValue(value);
    });
  }

dev-anton-ko and others added 2 commits July 4, 2025 13:05
Co-authored-by: Laffery <49607541+Laffery@users.noreply.github.com>
@dev-anton-ko dev-anton-ko requested a review from Laffery July 9, 2025 20:28
Comment thread components/input-number/input-number.component.ts
Comment thread components/input-number/input-number.component.ts Outdated

@Laffery Laffery left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HyperLife1119 HyperLife1119 merged commit 4c5666a into NG-ZORRO:master Jul 10, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants