import { Injectable } from ‘@angular/core’;
import {AngularFireDatabase, AngularFireObject} from “angularfire2/database”;
import { User } from ‘firebase/app’;
import { Profile } from ‘…/…/models/profile/profile.interface’;
@Injectable()
export class DataProvider {
profileObject: AngularFireObject;
constructor(public database: AngularFireDatabase) {
}
async saveProfile(user: User, profile: Profile){
this.profileObject = this.database.object('/profiles/${user.uid}');
try {
await this.profileObject.set(profile);
return true;
}
catch (e){
console.error(e);
return false;
}
}
}
import { Component } from ‘@angular/core’;
import { Profile } from ‘…/…/models/profile/profile.interface’;
import { DataProvider } from ‘…/…/providers/data/data’;
import { AuthProvider } from ‘…/…/providers/auth/auth’;
import { Subscription } from ‘rxjs/Subscription’;
import { User } from ‘firebase/app’;
@Component({
selector: ‘app-edit-profile-form’,
templateUrl: ‘edit-profile-form.html’
})
export class EditProfileFormComponent {
private authenticatedUser$: Subscription;
private authenticatedUser: User;
profile={} as Profile;
constructor(private data: DataProvider, private auth: AuthProvider) {
this.authenticatedUser$ = this.auth.getAuthenticatedUser().subscribe((user: User)=>
{
this.authenticatedUser= user;
})
}
async saveProfile(){
if (this.authenticatedUser) {
const result = await this.data.saveProfile(this.authenticatedUser,this.profile);
console.log(result);
}
}
}
when click on save button this error shows up
ERROR:
Error: Uncaught (in promise): Error: Reference.child failed: First argument was an invalid path = “/profiles/${user.uid}”. Paths must be non-empty strings and can’t contain “.”, “#”, “$”, “[”, or "]"
Error: Reference.child failed: First argument was an invalid path = “/profiles/${user.uid}”. Paths must be non-empty strings and can’t contain “.”, “#”, “$”, “[”, or “]”