akveo / akveo/ng2-smart-table

how to use pipes with async data

Đang mở
#1,240 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
1.6k
Fork
867
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

i try to use pipe but inside my pipe there's async data :
my pipe :
```
import { Pipe, PipeTransform } from "@angular/core";
import { VehiculeService } from "app/pages/fleetManagement/services/vehicule.service";
import { map } from "rxjs/operators";
@Pipe({
name: "convertVehicule"
})
export class ConvertVehiculePipe implements PipeTransform {
public result: any;
constructor(private vehicleService: VehiculeService) {}

transform(value) {
this.vehicleService
.getVehicules()
.pipe(
map((data: any = []) => {
let result;
for (let j = 0; j < data.length; j++) {
if (value === data[j].id) {
result = data[j].registration_number;
}
}
return result;
})
)
.subscribe(
(data: any = []) => {
console.log(data);
this.result = data;
}, // },
error => {
console.log(error);
}
);
console.log(this.result);
return this.result;
}
}
}
```

And in my component :
```

this.settings = { ...,
vehicule_fleet_id: {
title:"vehicle id",
type: "html",
editor: {
type: "custom",
component: SelectAssuranceComponent
},
valuePrepareFunction: cell => {
let formated = this.convertVehiclePipe.transform(cell);
return formated;
}
}
}
```
I did this but the console.log(this.result) is undefined, i don't know if the problem is the timing because the valuePrepareFunction is rendred directly or the problem is in the pipe function, precisely the variable scope inside the subscription to the observable and outside the subscription

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.