相关疑难解决方法(0)

Angular 2打字稿中的@Inject和@Injectable有什么区别

我不明白何时使用@Inject以及何时使用@Injectable?

  import {Component, Inject, provide} from '@angular/core';
    import {Hamburger} from '../services/hamburger'; 
    export class App {
       bunType: string;
       constructor(@Inject(Hamburger) h) {
         this.bunType = h.bun.type;
       }
     }
Run Code Online (Sandbox Code Playgroud)

和..

  import {Injectable} from '@angular/core';
    import {Bun} from './bun';
    @Injectable()
    export class Hamburger {
      constructor(public bun: Bun) {
      }
    }
Run Code Online (Sandbox Code Playgroud)

dependency-injection injectable typescript angular

9
推荐指数
2
解决办法
6787
查看次数