Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

javascript - How to make the custom key while pushing in the Angular 2 firebase database

My app.component.ts is as follows

import { Component } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

   list: FirebaseListObservable<any[]>;
    // listing: FirebaseObjectObservable<any[]>;
    constructor(private af:AngularFireDatabase) {
     this.list=this.af.list('/listings');
    //  this.addTask();
   }
   addTask(){
        this.list.push({ 
            name: 'Aswin',
            city:'kochi',
            bedrooms:'[email protected]',
            image:'9562096886',
            path:'10',
            price:'java',
            title:'3',
            type:'adipoli aanu'
      });
 }

}

My view page is like this

<input type="submit" (click)="addTask()"/>

Now when clicking the submit button it will push the values to angular2 firebase database.But the key name is random like KmMlBPniR8wpcyBMDOz.

I want to make the key should be custom,ie i want to give my own key name.how it should be possible,please help me? Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...