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

Resolvables override new InputSignals with raw value #998

Open
Lubjan opened this issue Dec 21, 2024 · 1 comment
Open

Resolvables override new InputSignals with raw value #998

Lubjan opened this issue Dec 21, 2024 · 1 comment

Comments

@Lubjan
Copy link

Lubjan commented Dec 21, 2024

The Angular team introduced signals but more importantly, signal inputs with Version 18.
The problem with the new signals is that they act as functions, which UI-Router doesn't seem to handle.

Example

@Component({
  selector: 'app-some',
  standalone: true,
  imports: [CommonModule],
  template: `{{ someInput() }}`,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SomeComponent {
  readonly someInput = input<string>(null);
}
const states: Ng2StateDeclaration[] = [
  {
    name: 'some-state',
    url: '/some',
    component: SomeComponent,
    resolve: {
      someInput: [async () => await of('Resolved value').toPromise()],
    },
  },
];

Expected behavior

  • UI-Router should resolve the someInput resolvable
  • The resolved value should be set for the signal input using someInput.set(value)
  • The input in the component should still be a usable signal input (access to someInput(), someInput.set(...), someInput.update(...), etc...)

Actual behavior

  • UI-Router resolves the value correctly
  • The resolved value is then set as a raw value, overriding the signal input (and making it a plain string in this example)
  • The signal input can no longer be used as intended (using someInput() in the component would throw [...] is not a function when navigated to)
@lindolo25
Copy link
Contributor

Hi @Lubjan this issue will be resolved by PR #995, it still a work in progress, but I hope I will finish it by the beginning of next year. With luck it will be merged soon after that!

Meanwhile you can use a setter and set the value of a signal

@Component({
  selector: 'app-some',
  standalone: true,
  imports: [CommonModule],
  template: `{{ someInput() }}`,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SomeComponent {
  readonly someValue = signal<string>(null);
  @Input() set someInput(value: string) {
    this.someValue.set(value);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants