解决类后为何不ngOnInit()
调用Injectable
?
码
import {Injectable, OnInit} from 'angular2/core';
import { RestApiService, RestRequest } from './rest-api.service';
@Injectable()
export class MovieDbService implements OnInit {
constructor(private _movieDbRest: RestApiService){
window.console.log('FROM constructor()');
}
ngOnInit() {
window.console.log('FROM ngOnInit()');
}
}
控制台输出
FROM constructor()
ngOnInit
逻辑移到Injectable
类的构造函数上?我刚刚记得阅读过,无论出于何种原因,都应将任何逻辑排除在构造函数之外。