Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NG0952: Input is required but no value is available yet. #55010

Closed
sysmat opened this issue Mar 23, 2024 · 4 comments
Closed

NG0952: Input is required but no value is available yet. #55010

sysmat opened this issue Mar 23, 2024 · 4 comments

Comments

@sysmat
Copy link

sysmat commented Mar 23, 2024

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

NG0952 Input is required but no value is available yet.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

export class UserComponent {
user = input.required<User>();
expired = signal<Date>(this.user()? this.user().expired: null);

changeExpired(){
  this.expired.set(new Date());
}

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.3.1
Node: 20.11.1
Package Manager: npm 10.2.4
OS: win32 x64

Angular: 17.3.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.1
@angular-devkit/build-angular   17.3.1
@angular-devkit/core            17.3.1
@angular-devkit/schematics      17.3.1
@schematics/angular             17.3.1
rxjs                            7.8.1
typescript                      5.4.3
zone.js                         0.14.4

Anything else?

if I try effect then I can not use this.expired.set

@JeanMeche
Copy link
Member

Hi, required inputs can only be read after the component is init (after ngOnInit()). By invoking user in the property initialization you're accessing a signal that hasn't been set yet.

In your case it looks like expired should be a computed input.

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Mar 23, 2024
@sysmat
Copy link
Author

sysmat commented Mar 24, 2024

  • this is very bad, can not use declarative programming
  • computed signal dos not have set or update function

@JeanMeche
Copy link
Member

Nested Signals (like DeepSignal from the signal Store) might me a good fit for you.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants