当我打开网页数据显示,但我更改组件并返回此组件数据不显示.它显示没有项目.我检查日志但没有运行到ngOnIt.ngOnIt在web strat或web reload上运行.
这是stock.service.ts
import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
import { Stock } from './stock.model';
@Injectable()
export class StockService {
stocksCollection: AngularFirestoreCollection<Stock>;
stocks: Observable<Stock[]>;
constructor(public afs: AngularFirestore) {
this.stocks = this.afs.collection('stocks').valueChanges();
}
getStock(){
return this.stocks;
}
}
Run Code Online (Sandbox Code Playgroud)
stock.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute,Params } from '@angular/router';
import { StockService } from '../shared/stock.service';
import { Stock } from '../shared/stock.model';
import …Run Code Online (Sandbox Code Playgroud)