Angular no provider for NameService

后端 未结 18 1926
遇见更好的自我
遇见更好的自我 2020-11-30 18:44

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

18条回答
  •  醉酒成梦
    2020-11-30 19:42

    Shockingly, the syntax has changed yet again in the latest version of Angular :-) From the Angular 6 docs:

    Beginning with Angular 6.0, the preferred way to create a singleton services is to specify on the service that it should be provided in the application root. This is done by setting providedIn to root on the service's @Injectable decorator:

    src/app/user.service.0.ts

    import { Injectable } from '@angular/core';
    
    @Injectable({
      providedIn: 'root',
    })
    export class UserService {
    }
    

提交回复
热议问题