Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 用于自定义管道的值为null_Angular - Fatal编程技术网

Angular 用于自定义管道的值为null

Angular 用于自定义管道的值为null,angular,Angular,顺便说一句,我是一个新的角度2。我已经创建了一个自定义管道,如下所示。然后我在视图中使用了该管道,如图所示。使用的值通过服务检索。我已打印出从服务检索到的数据,因为我已成功从服务获取数据 下面是从服务获取数据的代码 现在,我想要的是在加载数据后执行在我的视图中进行渲染的代码。怎么做 Angular2代码: HTML代码: 我只想在html视图中放一个if语句,这样在检索数据之前不会呈现视图,如下所示: <table *ngIf="myPurchaseItems" class="table"

顺便说一句,我是一个新的角度2。我已经创建了一个自定义管道,如下所示。然后我在视图中使用了该管道,如图所示。使用的值通过服务检索。我已打印出从服务检索到的数据,因为我已成功从服务获取数据

下面是从服务获取数据的代码

现在,我想要的是在加载数据后执行在我的视图中进行渲染的代码。怎么做

Angular2代码: HTML代码:
我只想在html视图中放一个if语句,这样在检索数据之前不会呈现视图,如下所示:

<table *ngIf="myPurchaseItems" class="table">
    <tr *ngFor="let data of myPurchaseItems | values">
      <td>{{data.Purchase_ID}}</td>
    </tr>
</table>

{{data.Purchase_ID}

希望这有帮助

沃尔,这个解决方案对你有帮助吗?:)
<table class="table">
    <tr *ngFor="let data of myPurchaseItems | values">
      <td>{{data.Purchase_ID}}</td>
    </tr>
</table>
ngOnInit() {
    this._service.getMyPracticeTest(this.uid).subscribe(data => {  
        this.myPurchaseItems = data;
        console.log("DATA HERE: ", this.myPurchaseItems) 
    });
}
<table *ngIf="myPurchaseItems" class="table">
    <tr *ngFor="let data of myPurchaseItems | values">
      <td>{{data.Purchase_ID}}</td>
    </tr>
</table>