如何在@Input Angular中传递异步?

时间:2019-03-09 15:14:04

标签: angular

我具有输入属性$xml = simplexml_load_string($xmlstring); $nodes = $xml->xpath("/root/trend/zone[@id = 809 and @name= 'AGi']/subzone[@id = 809 and @name = 'AGi']/text") ; $text = (string)$nodes[0] ; echo $text ; // I want this text.

[visitors]

如何像这样在异步上替换<app-visitor-component [visitors]="visitors"></app-visitor-component>

[visitors]="visitors"

3 个答案:

答案 0 :(得分:2)

如果您的服务是可观察的,则需要使用猫王运算符:

[visitors]="(service | async)?.currentUser"

答案 1 :(得分:1)

如果不按如下所述使用async,则可以将其发送为Observable

<app-child [visitors]="(service.currentUser| async)">

答案 2 :(得分:1)

使您要传递的变量set_target_properties(TARGET_LIB PROPERTIES COMPILE_OPTIONS "$<$<CONFIG:Debug>:/MTd>$<$<CONFIG:Release>:/MT>" ) // providers api import { Injectable } from '@angular/core'; import { Http, Headers, RequestOptions } from '@angular/http'; import 'rxjs/add/operator/map'; @Injectable() export class PostProvider { server: string = "http://localhost/IonicFYP/server.api/" constructor(public http: Http){ } postData(body, file){ let type = "application/json; charset=UTF-8"; let headers = new Headers({ 'Content-Type': type }); let options = new RequestOptions({ headers: headers}); return this.http.post(this.server + file, JSON.stringify(body), options) .map(res => res.json()); } }Observable

例如

Subject<T>

然后使用

BehaviourSubject<T>