Keep it as a best pratices that implements OnInit, OnDestroy. Then insidengOnInit, we call service to fetch data back. And inngOnDestroy, we unsubscribe the Observable. import {Component, ElementRef, EventEmitter, Output, OnInit, OnDestroy}from'angular2/core'; import {Observable}from'rxjs/R...
在Angular组件中,会看到这样类似的结构: export class HeroesComponent implements OnInit { hero = 'windstorm'; constructor() { } ngOnInit() { } } implements 是TypeScript 的语法,到底是什么意思呢? 在TypeScript中,有Class类和interface接口,接口只定义类型的成员或者方法的契约,就是如果你implements了我...
export interface OnInit 1. exported fromangular2/coredefined inangular2/src/core/linker/interfaces.ts (line 79) Implement this interface to execute custom initialization logic after your directive's data-bound properties have been initialized. ngOnInitis called right after the directive's data-bound...