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

feat(angular): setting props on a signal works #29453

Merged
merged 13 commits into from May 6, 2024
Merged

Conversation

sean-perkins
Copy link
Contributor

@sean-perkins sean-perkins commented May 3, 2024

Issue number: resolves #28876


What is the current behavior?

When assigning componentProps as inputs to an Angular component, we do Object.assign. When using the newer Angular Signals API for inputs the value of an input is a function:

myInput = input<string>('foo') // this is a function

The developer accesses the value of myInput in a template by doing myInput() since myInput is a function.

If a developer passes componentProps: { myInput: 'bar' } then the value of myInput is set to this string value, overriding the function. As a result, calling myInput() results in an error because myInput is a string not a function.

What is the new behavior?

  • Angular 14.1 introduced setInput which lets us hand off setting inputs to Angular. This will set input values properly even when using a Signals-based input.

Does this introduce a breaking change?

  • Yes
  • No

As part of this NavParams has been deprecated as it is incompatible with the setInput API. The old Object.assign worked to allow devs to get all of the componentProp key value pairs via NavParams even if they are not defined as Inputs. Using setInput will now throw an error, so developers need to create an @Input for each parameter. This means that NavParams has no purpose and can safely be retired in favor of Angular's Input API. Not removing NavParms would make it difficult for us to support new Angular APIs such as this Signals-based input API.

Other information

Dev build: 8.1.1-dev.11715021973.16675b67

You will need to update the Ionic config to opt-in to the new option:

useSetInputAPI: true,

Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ionic-framework ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 7:01pm

@sean-perkins sean-perkins marked this pull request as ready for review May 3, 2024 18:32
@sean-perkins sean-perkins requested a review from a team as a code owner May 3, 2024 18:32
Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

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

LGTM, verified in the build app and provided repro from the original issue.

@sean-perkins sean-perkins changed the title fix(angular): setting props on a signal works feat(angular): setting props on a signal works May 6, 2024
@sean-perkins sean-perkins merged commit 4640e04 into feature-8.2 May 6, 2024
57 checks passed
@sean-perkins sean-perkins deleted the FW-5923 branch May 6, 2024 22:12
@ntorrey
Copy link

ntorrey commented May 9, 2024

Woohoo! Can't wait for the 8.2 release. It will be good to finally move off of the dev version I've been using (not in production of course 😬). Thanks for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @ionic/angular package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants