I just started with Angular RC6. I imported HttpModule inside my @NgModule decorator.
However I get this exception: No provider for Array!
How can I fix this?
-- edit--: For some reason this error is caused by:
constructor(private myService: CustomService, public items: Item[]) { }
If a constructor of a service, component, or directive contains parameters, Angulars dependency injection tries to find a provider to get a value from it that it then passes to the constructor.
You don't have a provider registered for the type Item[]
.
Either
@Optional()
before public items: Item[]
so Angulars DI is allowed to ignore the parameter if it doesn't find a providerJust initialize the array outside the constructor and create it in the constructor i.e.
export class Animal{
public animals: Animal[]; //initializing outside the constructor
constructor(private animal: Animal) {
this.animals = new Array<Animal>(); //creating inside the constructor
animals.push(animal); //adding element to the array
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With