Angular2 global service provider

后端 未结 5 1557
轮回少年
轮回少年 2020-12-14 20:49
/app
        - app.component.ts 
        - app.component.html (hide/show: menu bar)
        - app.global.service.ts (Public varible LoginSuccess:boolean)
        - m         


        
5条回答
  •  无人及你
    2020-12-14 21:05

    As of final release (Angular 2.0.0) :

    Import the service and inject it in the providers array like so :

    import { GlobalService } from './app.global.service';
    
    //further down:
    @NgModule({
      bootstrap: [ App ],
      declarations: [
        // Your components should go here 
      ],
      imports: [ 
        // Your module imports should go here
      ],
      providers: [ 
        ENV_PROVIDERS // By Angular
        // Your providers should go here, i.e.
        GlobalService
      ]
    });
    

提交回复
热议问题