Angular no provider for NameService

后端 未结 18 1889
遇见更好的自我
遇见更好的自我 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:34

    Hi , You can use this in your .ts file :

    first import your service in this .ts file:

    import { Your_Service_Name } from './path_To_Your_Service_Name';
    

    Then in the same file you can add providers: [Your_Service_Name] :

     @Component({
          selector: 'my-app',
          providers: [Your_Service_Name],
          template: `
            

    Hello World

    ` })

提交回复
热议问题