I\'ve got a problem loading a class into an Angular component. I\'ve been trying to solve it for a long time; I\'ve even tried joining it all in a single file. What I have i
Add @Injectable to your service as:
export class NameService {
names: Array;
constructor() {
this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
}
getNames() {
return this.names;
}
}
and in your component add the providers as:
@Component({
selector: 'my-app',
providers: [NameService]
})
or if you want to access your service all over the application you can pass in app provider