Reputation: 255
I was trying to build my angular app but it fails because of this error
ERROR in : Can't resolve all parameters for SimpleLookupAddEditFormComponent
in C:/Users/lastr/Source/Repos/SMATA/Code/ng/smata-ng/src/app/system-
list/simple-lookup-add-edit/simple-lookup-add-edit.component.ts: (?, [object
Object], [object Object], [object Object]).
Here is the code of the COMPONENT. This is a base component. Is there anything missing here? maybe problems with the constructor properties?
import { Component, OnInit } from '@angular/core';
import { SimpleLookupBaseService } from '../services/simple-lookup-base/simple-lookup-base.service';
import { ActivatedRoute, Router } from '@angular/router';
import validationEngine from "devextreme/ui/validation_engine";
import notify from 'devextreme/ui/notify';
@Component({
selector: 'app-simple-lookup-add-edit',
templateUrl: './simple-lookup-add-edit.component.html',
styleUrls: ['./simple-lookup-add-edit.component.css']
})
export class SimpleLookupAddEditFormComponent implements OnInit {
newSystemList: {};
isEditMode:boolean = true;
selectedSystemList: any;
title: string;
saveButtonText: string;
isPopupVisible:boolean = false;
entityId:any;
constructor(
protected _systemListTitle : string,
protected _svc: SimpleLookupBaseService,
protected _router: Router,
protected _route: ActivatedRoute
)
{}
............
.....
}
Upvotes: 4
Views: 1887
Reputation: 54821
ERROR in : Can't resolve all parameters for SimpleLookupAddEditFormComponent in C:/Users/lastr/Source/Repos/SMATA/Code/ng/smata-ng/src/app/system- list/simple-lookup-add-edit/simple-lookup-add-edit.component.ts: (?, [object Object], [object Object], [object Object]).
The ?
question mark in the error message tells which parameter in the constructor is unknown.
constructor(
protected _systemListTitle : string,
protected _svc: SimpleLookupBaseService,
protected _router: Router,
protected _route: ActivatedRoute
)
The first parameter is triggering the ?
question mark.
The type string
is not an injectable type. Angular injector uses the type of the parameters to infer what the injectable
provider that should be used.
To inject a string
parameter you have to provide a token in one of your NgModule
definitions.
export const LIST_TITLE: InjectionToken<string> = new InjectionToken<string>('LIST_TITLE');
@NgModule({
providers: [{provide: LIST_TITLE, useValue: 'My List Title'}]
})
Now you can manually inject the token into your constructor.
constructor(
@Inject(LIST_TITLE) protected _systemListTitle : string,
protected _svc: SimpleLookupBaseService,
protected _router: Router,
protected _route: ActivatedRoute
)
Upvotes: 5