例子:
import { Injectable } from '@angular/core';
let count = 0;
@Injectable()
export class MyService {
seed: number;
_count: number;
constructor(){
this.seed = Number((Math.random() * 100).toFixed(0));
this._count = count++;
console.log('diablo constructor called: ' + this.seed);
}
}
這個單例行為在
Angular DI幫助文檔裡有提到:
https://angular.io/guide/glossary#injector