这是我的模板:
<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上则不行.如果我禁用模板中的按钮,相同的代码将起作用.
我的用例是:我必须通过对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)