- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Firebase 构建一个 Angular 应用程序,以将图像上传到数据库并从那里检索它。
import {Injectable} from '@angular/core';
import {AngularFireDatabase, AngularFireList} from 'angularfire2/database';
import * as firebase from 'firebase';
import {FileUpload} from '../uploadingpage/fileupload';
@Injectable()
export class UploadFileService {
constructor(private db: AngularFireDatabase) {}
getFileUploads (): AngularFireList{
return this.db.list('/uploads');
}
private basePath = '/uploads';
fileUploads: AngularFireList;
pushFileToStorage(fileUpload: FileUpload, progress: {percentage: number}) {
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`${this.basePath}/${fileUpload.file.name}`).put(fileUpload.file);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) => {
// in progress
const snap = snapshot as firebase.storage.UploadTaskSnapshot
progress.percentage = Math.round((snap.bytesTransferred / snap.totalBytes) * 100)
},
(error) => {
// fail
console.log(error)
},
() => {
// success
fileUpload.url = uploadTask.snapshot.downloadURL
fileUpload.name = fileUpload.file.name
this.saveFileData(fileUpload)
}
);
}
private saveFileData(fileUpload: FileUpload) {
this.db.list(`${this.basePath}/`).push(fileUpload);
}
}
import { Component, OnInit } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, AngularFireObject } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase';
import { FirebaseAuthService } from '../auth/firebase-auth.service';
import { ItemService } from '../services/item.service';
import { UploadFileService } from '../services/upload-file.service';
import { FileUpload } from './fileupload';
@Component({
selector: 'app-uploadingpage',
templateUrl: './uploadingpage.component.html',
styleUrls: ['./uploadingpage.component.css']
})
export class ProfileComponent implements OnInit {
//for image
selectedFiles: FileList;
currentFileUpload: FileUpload;
progress: {percentage: number} = {percentage: 0};
constructor(
private afDb: AngularFireDatabase,
private _auth: FirebaseAuthService,
private itemService: ItemService,
private uploadService: UploadFileService
) { }
ngOnInit() {
}
//for image
selectFile(event) {
this.selectedFiles = event.target.files;
}
//for image
upload() {
const file = this.selectedFiles.item(0)
this.currentFileUpload = new FileUpload(file);
this.uploadService.pushFileToStorage(this.currentFileUpload, this.progress);
}
signOut(){
this._auth.signOut();
window.location.href = "";
}
}
import { Component, OnInit } from '@angular/core';
//additional imports
import { ItemService } from '../services/item.service';
import {FileUpload} from '../uploadingpage/fileupload';
import {UploadFileService} from '../services/upload-file.service';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import * as firebase from 'firebase';
@Component({
selector: 'app-admin',
templateUrl: './displaypage.component.html',
styleUrls: ['./displaypage.component.css']
})
export class DisplaypageComponent implements OnInit {
fileUploads: AngularFireList;
constructor(private itemService: ItemService, private uploadService: UploadFileService) { }
ngOnInit() {
this.itemService.getItems().subscribe(items => {
this.items = items;
});
this.uploadService.getFileUploads().valueChanges().subscribe(result=>{
this.fileUploads = result;
});
}
}
现在虽然我可以上传图像并从数据库中检索它,但是我的终端显示时总是出现错误 Type 'FileUpload[][]' is not assignable to type 'AngularFireList
Property 'query' is missing in type 'FileUpload[][]'.
知道为什么会这样吗?
如有任何帮助,我们将不胜感激。谢谢。
câu trả lời hay nhất
你不需要在这里使用 AngularFireList 类型,
创建一个类
export class Upload {
$key: string;
tên: chuỗi;
url: chuỗi;
file: File;
progress:number;
timestamp: Date = new Date();
constructor(file: File) {
this.file = file;
}
}
在您的服务中,
uploads: Observable;
getUploads() {
this.uploads = this.db.list(this.basePath).snapshotChanges().map((actions) => {
return actions.map((a) => {
const data = a.payload.val();
const $key = a.payload.key;
return { $key, ...data };
});
});
return this.uploads;
}
在你的组件中,
uploads: Observable;
ngOnInit() {
this.uploads = this.uploadService.getUploads();
}
并使用 |async 改变你的 div
关于angular - 类型 'FileUpload[][]' 不可分配给类型 'AngularFireList
Tôi đang cố gắng viết một thư viện khá đa hình. Tôi rơi vào tình huống dễ thể hiện điều đó nhưng lại khó nói về nó hơn. Nó trông hơi giống thế này: {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE
Có ai có thể giải thích cách biểu thức này hoạt động không? type = type || 'any'; Điều này có nghĩa là sử dụng 'any' nếu loại không được xác định? Câu trả lời hay nhất Nếu loại là "falsy" (tức là sai hoặc không xác định
Tôi có một giao diện, trong IAnimal.fs, không gian tên Kingdom loại IAnimal = thành viên trừu tượng Eat : Food -> unit và một thành công khác
Câu hỏi này đã có câu trả lời ở đây: đã đóng cửa 10 năm trước. Có thể trùng lặp: Sự khác biệt giữa giá trị (loại) và loại (va)
Trong C#, có sự khác biệt giữa mặc định (Nullable) không? (hoặc mặc định(dài?) ) và mặc định(dài) ? Long chỉ là một ví dụ, nó có thể là bất kỳ loại cấu trúc nào khác. hầu hết
Giả sử tôi có một lớp trường hợp: case class Foo(num: Int, str: String, bool: Boolean) Bây giờ tôi cũng có một trình bao bọc đơn giản: seal trait Wrapper[
Câu hỏi này đã có câu trả lời ở đây: Tạo loại đại biểu C# với tham số ref khi chạy (1 câu trả lời) Đã đóng 2 năm trước. Để tạo một đại biểu một cách nhanh chóng (dele
Tôi đang cố gắng lấy dct của một hình ảnh. Lúc đầu, tôi gặp lỗi Chức năng/tính năng không được triển khai (DCT kích thước lẻ không được triển khai
Tôi đang cố gắng sử dụng AFPropertyListRequestOperation của AFNetworking, nhưng khi tôi cố tải xuống, tôi gặp lỗi Expected content type {("application/x-plist")},
Tôi đang gặp lỗi bên dưới. Tôi biết mã này có nghĩa là gì, nhưng tôi không biết giao diện sẽ trông như thế nào: Phần tử ngầm có loại 'bất kỳ' vì biểu thức chỉ mục là
Tôi cố gắng mở rộng SignalType từ ReactiveCocoa sang ErrorType tùy chỉnh, mã như sau enum MyError: ErrorType { // .. case }
Tôi không thể tìm thấy câu trả lời trong bất kỳ câu hỏi nào khác. Giả sử tôi có một siêu lớp trừu tượng Tóm tắt0, có hai lớp con Concrete1 và Concrete1. Tôi muốn có thể định nghĩa các lớp trong Tóm tắt0
Tôi muốn biết tại sao chỉ mục này không được sử dụng trong loại RANGE mà trong INDEX: Index: CREATE INDEX myindex ON order(order_date);
Tôi đang sử dụng RxJava và bây giờ tôi cố gắng đăng ký một thiết bị có thể quan sát được bằng cách cung cấp lambda: observableProvider.stringForKey(CURRENT_DELETED_ID) .sub
Tôi đã thử hầu hết mọi giải pháp cho vấn đề, bao gồm cả. Còn nhiều cách khác để sử dụng app.use(express.static('public')) cho loại được cung cấp, nhưng dường như tôi không thể tìm ra giải pháp cho việc này. index.js: imp
Bộ chọn CSS nào sau đây nhanh hơn? input[type="submit"] { /* styles */ } hoặc [type="submit"] { /* styles */ } đều ổn
Tôi không biết có gì sai với thiết lập này, tôi nhận được tất cả các chú thích (@Controller, @Repository, @Service) trong IDEA và nó hiển thị Bean ở bên trái của số dòng rồi chuyển đến Bean đó. Đây là lỗi: 14-
Tôi đã làm theo lời khuyên khi đăng ký hàm java làm hàm gọi lại trong hàm C và tôi có thể sử dụng các loại "đơn giản" như số nguyên và chuỗi cho hàm gọi lại, ví dụ: jstring j
Có một số lớp java, được tải vào cơ sở dữ liệu Oracle (phiên bản 11g) và các trình bao bọc hàm pl/sql: tạo hoặc thay thế hàm getDataFromJava( in_uLis
Tôi đã lấy mã từ lệnh gọi lại hoạt ảnh css của David Walsh và sửa đổi nó thành TypeScript. Tuy nhiên, tôi gặp lỗi và không biết tại sao: giao diện IBrowserPrefix { [
Tôi là một lập trình viên xuất sắc, rất giỏi!