小编Anu*_*mar的帖子

如何使用按钮样式在Ionic 2+中创建自定义文件输入?

这是我的模板:

<label>{{label}}</label>
<input type="file" (change)="fileUpload($event)" id="file-input" style="position:absolute; top: -999999px" #fileInp>
<button ion-button (click)="onClick()">Upload</button>
Run Code Online (Sandbox Code Playgroud)

和ts文件:

@ViewChild('fileInp') fileInput: ElementRef;
@Input() label: string;
@Output() data = new EventEmitter<FormData>();

fileUpload(event) {
  let fd = new FormData();
  fd.append('file', event.srcElement.files[0]);
  this.data.emit(fd);
}

onClick() {
  this.fileInput.nativeElement.click();
}
Run Code Online (Sandbox Code Playgroud)

在Android和浏览器中一切正常,但在iOS上则不行.如果我禁用模板中的按钮,相同的代码将起作用.

cordova ionic2 ionic3 angular

6
推荐指数
2
解决办法
7449
查看次数

switchMap 与 forkJoin 不显示结果

我的用例是:我必须通过对MeasurementUnit每个ProductCategory进行 api 调用来获取每个ProductCategory.

这是我的一项服务的片段。当findAll在组件中订阅时,它永远不会收到值。但是,某些值会按标记进行记录。我究竟做错了什么?

是否有其他方法可以获得相同的结果?

findAll(): Observable<ProductCategory[]> {
  return this.http.get<UnresolvedProductCategory[]>(`product-categories/`).pipe(
    tap(categories => console.log(categories)),  // is logged
    switchMap(categories => forkJoin(categories.map(this.resolveCategory.bind(this)))),
    tap(categories => console.log({ finalCategories: categories })) // is not logged
  );
}

resolveCategory(category: UnresolvedProductCategory): Observable<ProductCategory> {
  return this.measurementUnits.findOne(category.measurementUnit).pipe(
    map(measurementUnit => ({ ...category, measurementUnit })),
    tap(category => console.log({ category })) // is logged for each category
  );
}
Run Code Online (Sandbox Code Playgroud)

rxjs angular

2
推荐指数
1
解决办法
1595
查看次数

标签 统计

angular ×2

cordova ×1

ionic2 ×1

ionic3 ×1

rxjs ×1