【问题标题】:unable to bind values from observable IONIC无法绑定来自可观察 IONIC 的值
【发布时间】:2020-08-22 09:03:01
【问题描述】:

我正在尝试将存储为可观察的 api 响应的 JSON 响应的属性绑定到离子标题。但无法让它工作。有人可以帮我解决其中的问题吗?

page.ts

export class DisplayPage implements OnInit {
Category : any;
result: Observable<any>;
constructor(private route: ActivatedRoute, private router: Router, private myService: MyService) {
this.Category = this.route.snapshot.params.Category;
 var id = this.route.snapshot.params.id;
 this.result = this.myService.result(this.Category,id);
 this.result.subscribe(res => console.log(res.name));//can see the response here logged
}

page.html

<ion-header>
  <ion-toolbar>
    <ion-title>{{result.name | async}}</ion-title> *** not working ***
  </ion-toolbar>
</ion-header>

<ion-content>

</ion-content>

我也尝试过 ng-bind,但无法成功。 API调用很好。响应就在那里,因为代码中可以控制台记录它。但不绑定到页面。

【问题讨论】:

    标签: json ionic-framework


    【解决方案1】:

    也许你可以通过以下方式实现它:

     <ng-container *ngIf="result | async as res">
            <ion-title>{{res.name}}</ion-title>
        </ng-container>
    

    【讨论】:

      猜你喜欢
      • 2012-11-02
      • 2014-06-23
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多