Angular no provider for NameService

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

    The error No provider for NameService is a common issue that many Angular2 beginners face.

    Reason: Before using any custom service you first have to register it with NgModule by adding it to the providers list:

    Solution:

    @NgModule({
        imports: [...],
        providers: [CustomServiceName]
    })
    

提交回复
热议问题