我们正忙着填写注册表,用户需要上传图像,因此我们决定将图像保存到Google Firebase。
尝试将图像上传到Firebase时出现此错误:
No provider for InjectionToken angularfire2.app.options!
我的app.module.ts文件:
other imports
import { AngularFireStorage } from 'angularfire2/storage';
import { AngularFireModule } from '@angular/fire';
import { AngularFireDatabaseModule } from '@angular/fire/database';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
AngularFireModule.initializeApp({
apiKey: "----------",
authDomain: "-------------",
projectId: "------------",
storageBucket: "---------",
}),
AngularFireDatabaseModule,
ReactiveFormsModule,
CommonModule,
NgxGaugeModule,
NgxChartsModule,
HttpClientModule,
AgmCoreModule.forRoot({
apiKey: 'AIzaSyAir4tXhx3X-wcdZnhe8TLlo9J2m_AKx6w'
}),
PerfectScrollbarModule,
CalendarModule.forRoot({
provide: DateAdapter,
useFactory: adapterFactory
}),
SharedModule,
PipesModule,
routing
],
declarations: [
*all declarations here*
],
entryComponents:[
VerticalMenuComponent
],
providers: [
AppSettings,
{ provide: PERFECT_SCROLLBAR_CONFIG, useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG },
{ provide: OverlayContainer, useClass: CustomOverlayContainer },
AngularFireStorage
],
bootstrap: [AppComponent]
})
export class AppModule { }
我要执行上传的.ts中的导入:
import { AngularFireStorage } from 'angularfire2/storage';
我试图上传图像的ts函数:
public onSubmit(event) {
const randomId = Math.random().toString(36).substring(2);
this.ref = this.afStorage.ref(randomId);
this.task = this.ref.put(this.files[0]);
this.uploadProgress = this.task.percentageChanges();
this.downloadURL = this.task.downloadURL();
alert(this.downloadURL);
}
onSelectedFile(event){
if (event.target.files.length > 0){
event.target.files[0].name = this.SubmitData.IDNum;
this.files = event.target.files[0];
}
}