试图将JSON响应的属性与可观察到的api响应绑定到离子标题。但是无法使其正常工作。有人可以帮我解决其中的问题吗?
page.ts
while True:
arrival_hour = int(input("Enter your time of arrival | No Parking from Midnight 00:00 to 07:59 Am: "))
if 8 <= arrival_hour <= 24:
break
else:
print("Wrong Input of Arrival Hour, Please Try Again")
continue
page.html
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
}
我也尝试了ng-bind,但是无法正常工作。 API调用很好。响应在那里,因为代码中能够控制台记录它。但不绑定到页面。
答案 0 :(得分:2)
也许您可以通过以下方式实现它:
<ng-container *ngIf="result | async as res">
<ion-title>{{res.name}}</ion-title>
</ng-container>