[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => https://github.com/ngxs/store/blob/master/CONTRIBUTING.md
[ ] Other... Please describe:
!!! Before read this, i'm using Angular 8 with ivy compiler !!!
When i have a any service on DI in the constructor of State i have always this error . Can't resolve all parameters for NavigatorState: (?).
This is my app.module
@NgModule({
declarations: [
AppComponent,
],
imports: [
.....,
// Ngxs
NgxsModule.forRoot([
LayoutState,
NavigatorState
], {
developmentMode: !environment.production,
}),
.....
The layoutState not have a construction with DI
@State<LayoutStateModel>({
name: 'layout',
defaults: defaultLayoutStateModel
})
export class LayoutState {
}
And the State who i am blocked
@State<NavigatorStateModel>({
name: 'navigator',
defaults: {
items: []
}
})
export class NavigatorState {
constructor(private readonly _router: Router) {
}
@Action(Navigate)
add(ctx: StateContext<NavigatorStateModel>, { payload }: Navigate) {
this._router.navigate([payload]);
}
}
If you want my angularCompilerOptions
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableIvy": true
}
Libs:
- @angular/core version: 8.2.0
- @angular/compiler-cli version: 8.2.0
- @ngxs/store version: ^3.5.0-dev.master-07d305f
For Tooling issues:
- Node version: 10.16.0
- Platform: Mac
@workfel please add repo for reproduce
How can I fix this? Using latest version of Angular and:
@ngxs/devtools-plugin": "^3.6.2",
@ngxs/store": "^3.6.2",
Still getting this error
Error: Can't resolve all parameters for AppState: (?).
Add Injectable decorator for your state class
Ivy requires to decorate all providers with the @Injectable() decorator
then the Ivy compatible code should look like this:
import { Injectable } from '@angular/core';
import { State } from '@ngxs/store';
@State
defaults: ['USA', 'Mexico', 'Canada']
})
@Injectable()
export class CountriesState {}
After making the state class Injectable will we still use the selectors?
@leobororo what do you mean?
@debender495 why is it necessary to add Injectable decorator if official documentation does not mentioned it: https://www.ngxs.io/concepts/state. Can you please explain or refer to the doc?
@teohirs Becase need update docs
@splincode That worked for me - thank you sir!
Most helpful comment
Add Injectable decorator for your state class