行为主体正在控制台中加载数据,但是模板在角度上为空白

I am working on an angular app where I am subscribing data in service and emitting data using Subject in component.html and in component.ts I am subscribing to get the latest value.

我的问题是,刷新页面时,我在控制台中获取了数据,但在模板上却看不到它。另外,当我再次单击路由器链接时,我可以在第一次单击后看到数据。

服务

  public_Data= new BehaviorSubject<any>(null);
  getDemo2(){
    this.http.get<UPost[]>(`https://write-your-heart-out-b338b.firebaseio.com/post/${this.uid}/public.json`)
    .pipe(
      map(responseData => {
        const postsArray: UPost[] = [];
        for (const key in responseData) {
          if (responseData.hasOwnProperty(key)) {
            postsArray.push({ ...responseData[key] });
          }
        }
        return postsArray;
      })
    )
    .subscribe(posts => {
      this.public_Data.next(posts)


      this.combine()
    });
  }

component.ts

 allpost: UPost[] = [];
  constructor(  private acrud: ACrudService) { }

  ngOnInit(): void {
    //this.acrud.getAllData()

    this.acrud.getDemo1();
    this.acrud.getDemo2()
    console.log("oninitnt methid")


   this.allSub= this.acrud.public_Data.subscribe(d=>{
      console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",d)
    })

component.html

 <div class="card row" *ngFor="let i of allpost  ; let c = index">
      <div class="col-md-9 col-xs-9 main-content">
        <h2 class="title">{{ i.title }}</h2>
        <p>{{ i.description }}</p>
</div>
</div>
评论