0
參考代碼:角2 DI查詢
https://plnkr.co/edit/j5qPROsWX2mGCQMIigee?p=info
它去是這樣的:
import {Component, Inject, provide} from 'angular2/core';
import {Hamburger} from '../services/hamburger';
@Component({
selector: 'app',
template: `Bun Type1: {{ bunType1 }}
<br/>
Are these same instances : {{equality}}
`
})
export class App {
bunType: string;
constructor(@Inject(Hamburger) h1, @Inject(Hamburger) h2) {
this.bunType1 = h1.bun.type;
if (h1 === h2) {
this.equality = 'true'; //this is the outcome
} else {
this.equality = 'false';
}
}
}
在App類中,我們注入兩個不同的變量h1和h2。 我打電話給他們不同,因爲我相信angular2框架確實像
h1 = new Hamburger()
h2 = new Hamburger()
現在注入兩個不同的對象到應用程序的構造。如果是這種情況,那麼我們如何得到結果(h1 === h2)= true?