Error: No provider for Number!

91 views
Skip to first unread message

Bernd Wachter

unread,
May 25, 2017, 8:00:26 AM5/25/17
to Angular and AngularJS discussion
Hello,

i have this Class in my Angular 4 Project when i call this function from another Service class

let newItem = this.item(id, name, price, quantity, data, imagePath);

and want to give the Parameters to the Item Class

i become always the Error:
ERROR Error: Uncaught (in promise): Error: No provider for Number!



import { Injectable } from '@angular/core';

@Injectable()
export class Item {
constructor(private id: number,
private articleId: string,
private name: string,
private price: string,
private quantity: number,
private data: string,
private imagePath: string){}

}




what i do wrong here ?
i want to give the Parameters to the Item Class and make there some Calculations
and want to give a Array with the calculated Data back...

Thanks for help
Benny

Oussama Dinia

unread,
May 25, 2017, 10:10:30 AM5/25/17
to ang...@googlegroups.com
you need to add the service to the providers array in your module definition. 

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Oussama Dinia

unread,
May 25, 2017, 10:17:51 AM5/25/17
to ang...@googlegroups.com
i gave wrong answers just looked back at the question, sorry about that 

Sander Elias

unread,
May 25, 2017, 11:39:20 AM5/25/17
to Angular and AngularJS discussion
Hi Benny,

The constructor is used by Angular to inject dependencies into a service. You can't use that to 'set up' your vars. Create another class, and use a method in your service make a factory out of that.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages