angular-docs-cn/public/docs/_examples/lifecycle-hooks/ts/app/logger.service.ts

20 lines
333 B
TypeScript

import {Injectable} from 'angular2/core';
@Injectable()
export class LoggerService {
logs:string[] = [];
log(msg:string, noTick:boolean = false) {
if (!noTick) { this.tick(); }
this.logs.push(msg);
}
clear() {this.logs.length = 0;}
tick() {
setTimeout(() => {
// console.log('tick')
}, 0);
}
}