Angular no provider for NameService

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

    Blockquote

    Registering providers in a component

    Here's a revised HeroesComponent that registers the HeroService in its providers array.

    import { Component } from '@angular/core';
    
    import { HeroService } from './hero.service';
    
    @Component({
      selector: 'my-heroes',
      providers: [HeroService],
      template: `
      `
    })
    export class HeroesComponent { }
    

提交回复
热议问题