error - Update username in firebase database using ionic v3











up vote
0
down vote

favorite












i want add username field in firebase, as all said we cant add direct username field in firebase. So i am trying to add via update method. Here i got code with this if i add value in code that way working but i don't know how can i add value via input.



file.ts



this.fAuth.auth.onAuthStateChanged(function(user) {

if (user) {

// Updates the user attributes:

user.updateProfile({ // <-- Update Method here

displayName: "Goku",
photoURL: "https://example.com/jane-q-user/profile.jpg"

}).then(function() {

// Profile updated successfully!
// "NEW USER NAME"

var displayName = user.displayName;
// "https://example.com/jane-q-user/profile.jpg"
var photoURL = user.photoURL;

}, function(error) {
// An error happened.
});

}
});


file.html



<form [formGroup]="myForm">
<ion-list>

<ion-item>
<ion-label floating>Username</ion-label>
<ion-input formControlName="displayName" type="text" [(ngModel)]="user.displayName"></ion-input>
</ion-item>
</form>

</ion-content>


please help me...










share|improve this question






















  • Hello, did you try my answer?
    – Peter Haddad
    2 days ago












  • yes, i did but but not solve
    – user9088454
    2 days ago










  • what is the problem? Didn't you want to get the value from html to ts?
    – Peter Haddad
    2 days ago















up vote
0
down vote

favorite












i want add username field in firebase, as all said we cant add direct username field in firebase. So i am trying to add via update method. Here i got code with this if i add value in code that way working but i don't know how can i add value via input.



file.ts



this.fAuth.auth.onAuthStateChanged(function(user) {

if (user) {

// Updates the user attributes:

user.updateProfile({ // <-- Update Method here

displayName: "Goku",
photoURL: "https://example.com/jane-q-user/profile.jpg"

}).then(function() {

// Profile updated successfully!
// "NEW USER NAME"

var displayName = user.displayName;
// "https://example.com/jane-q-user/profile.jpg"
var photoURL = user.photoURL;

}, function(error) {
// An error happened.
});

}
});


file.html



<form [formGroup]="myForm">
<ion-list>

<ion-item>
<ion-label floating>Username</ion-label>
<ion-input formControlName="displayName" type="text" [(ngModel)]="user.displayName"></ion-input>
</ion-item>
</form>

</ion-content>


please help me...










share|improve this question






















  • Hello, did you try my answer?
    – Peter Haddad
    2 days ago












  • yes, i did but but not solve
    – user9088454
    2 days ago










  • what is the problem? Didn't you want to get the value from html to ts?
    – Peter Haddad
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











i want add username field in firebase, as all said we cant add direct username field in firebase. So i am trying to add via update method. Here i got code with this if i add value in code that way working but i don't know how can i add value via input.



file.ts



this.fAuth.auth.onAuthStateChanged(function(user) {

if (user) {

// Updates the user attributes:

user.updateProfile({ // <-- Update Method here

displayName: "Goku",
photoURL: "https://example.com/jane-q-user/profile.jpg"

}).then(function() {

// Profile updated successfully!
// "NEW USER NAME"

var displayName = user.displayName;
// "https://example.com/jane-q-user/profile.jpg"
var photoURL = user.photoURL;

}, function(error) {
// An error happened.
});

}
});


file.html



<form [formGroup]="myForm">
<ion-list>

<ion-item>
<ion-label floating>Username</ion-label>
<ion-input formControlName="displayName" type="text" [(ngModel)]="user.displayName"></ion-input>
</ion-item>
</form>

</ion-content>


please help me...










share|improve this question













i want add username field in firebase, as all said we cant add direct username field in firebase. So i am trying to add via update method. Here i got code with this if i add value in code that way working but i don't know how can i add value via input.



file.ts



this.fAuth.auth.onAuthStateChanged(function(user) {

if (user) {

// Updates the user attributes:

user.updateProfile({ // <-- Update Method here

displayName: "Goku",
photoURL: "https://example.com/jane-q-user/profile.jpg"

}).then(function() {

// Profile updated successfully!
// "NEW USER NAME"

var displayName = user.displayName;
// "https://example.com/jane-q-user/profile.jpg"
var photoURL = user.photoURL;

}, function(error) {
// An error happened.
});

}
});


file.html



<form [formGroup]="myForm">
<ion-list>

<ion-item>
<ion-label floating>Username</ion-label>
<ion-input formControlName="displayName" type="text" [(ngModel)]="user.displayName"></ion-input>
</ion-item>
</form>

</ion-content>


please help me...







firebase ionic-framework ionic3 firebase-authentication






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









user9088454

156




156












  • Hello, did you try my answer?
    – Peter Haddad
    2 days ago












  • yes, i did but but not solve
    – user9088454
    2 days ago










  • what is the problem? Didn't you want to get the value from html to ts?
    – Peter Haddad
    2 days ago


















  • Hello, did you try my answer?
    – Peter Haddad
    2 days ago












  • yes, i did but but not solve
    – user9088454
    2 days ago










  • what is the problem? Didn't you want to get the value from html to ts?
    – Peter Haddad
    2 days ago
















Hello, did you try my answer?
– Peter Haddad
2 days ago






Hello, did you try my answer?
– Peter Haddad
2 days ago














yes, i did but but not solve
– user9088454
2 days ago




yes, i did but but not solve
– user9088454
2 days ago












what is the problem? Didn't you want to get the value from html to ts?
– Peter Haddad
2 days ago




what is the problem? Didn't you want to get the value from html to ts?
– Peter Haddad
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













To take the value from the html, try the following:



<form [formGroup]="myForm" (ngSubmit)="onSubmit()">
<ion-list>
<ion-item>
<ion-label floating>Username</ion-label>
<ion-input formControlName="displayName" type="text" [(ngModel)]="displayName"></ion-input>
</ion-item>
<ion-item>
<button ion-button type="submit" [disabled]="myForm.invalid">Submit</button>
</ion-item>
</ion-list>
</form>


Then in the .ts, do the following:



ngOnInit()
{
this.myForm = this.fb.group({
displayName : ['', Validators.required],
});
}

onSubmit()
{
if(this.myForm.valid)
{
this.displayName = this.myForm.get('displayName').value;
console.log(this.displayName);
}
}


this.displayName will contain the value of the ion-input, do not forget to declare the property displayName under the class declaration.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350012%2ferror-update-username-in-firebase-database-using-ionic-v3%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    To take the value from the html, try the following:



    <form [formGroup]="myForm" (ngSubmit)="onSubmit()">
    <ion-list>
    <ion-item>
    <ion-label floating>Username</ion-label>
    <ion-input formControlName="displayName" type="text" [(ngModel)]="displayName"></ion-input>
    </ion-item>
    <ion-item>
    <button ion-button type="submit" [disabled]="myForm.invalid">Submit</button>
    </ion-item>
    </ion-list>
    </form>


    Then in the .ts, do the following:



    ngOnInit()
    {
    this.myForm = this.fb.group({
    displayName : ['', Validators.required],
    });
    }

    onSubmit()
    {
    if(this.myForm.valid)
    {
    this.displayName = this.myForm.get('displayName').value;
    console.log(this.displayName);
    }
    }


    this.displayName will contain the value of the ion-input, do not forget to declare the property displayName under the class declaration.






    share|improve this answer

























      up vote
      0
      down vote













      To take the value from the html, try the following:



      <form [formGroup]="myForm" (ngSubmit)="onSubmit()">
      <ion-list>
      <ion-item>
      <ion-label floating>Username</ion-label>
      <ion-input formControlName="displayName" type="text" [(ngModel)]="displayName"></ion-input>
      </ion-item>
      <ion-item>
      <button ion-button type="submit" [disabled]="myForm.invalid">Submit</button>
      </ion-item>
      </ion-list>
      </form>


      Then in the .ts, do the following:



      ngOnInit()
      {
      this.myForm = this.fb.group({
      displayName : ['', Validators.required],
      });
      }

      onSubmit()
      {
      if(this.myForm.valid)
      {
      this.displayName = this.myForm.get('displayName').value;
      console.log(this.displayName);
      }
      }


      this.displayName will contain the value of the ion-input, do not forget to declare the property displayName under the class declaration.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        To take the value from the html, try the following:



        <form [formGroup]="myForm" (ngSubmit)="onSubmit()">
        <ion-list>
        <ion-item>
        <ion-label floating>Username</ion-label>
        <ion-input formControlName="displayName" type="text" [(ngModel)]="displayName"></ion-input>
        </ion-item>
        <ion-item>
        <button ion-button type="submit" [disabled]="myForm.invalid">Submit</button>
        </ion-item>
        </ion-list>
        </form>


        Then in the .ts, do the following:



        ngOnInit()
        {
        this.myForm = this.fb.group({
        displayName : ['', Validators.required],
        });
        }

        onSubmit()
        {
        if(this.myForm.valid)
        {
        this.displayName = this.myForm.get('displayName').value;
        console.log(this.displayName);
        }
        }


        this.displayName will contain the value of the ion-input, do not forget to declare the property displayName under the class declaration.






        share|improve this answer












        To take the value from the html, try the following:



        <form [formGroup]="myForm" (ngSubmit)="onSubmit()">
        <ion-list>
        <ion-item>
        <ion-label floating>Username</ion-label>
        <ion-input formControlName="displayName" type="text" [(ngModel)]="displayName"></ion-input>
        </ion-item>
        <ion-item>
        <button ion-button type="submit" [disabled]="myForm.invalid">Submit</button>
        </ion-item>
        </ion-list>
        </form>


        Then in the .ts, do the following:



        ngOnInit()
        {
        this.myForm = this.fb.group({
        displayName : ['', Validators.required],
        });
        }

        onSubmit()
        {
        if(this.myForm.valid)
        {
        this.displayName = this.myForm.get('displayName').value;
        console.log(this.displayName);
        }
        }


        this.displayName will contain the value of the ion-input, do not forget to declare the property displayName under the class declaration.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Peter Haddad

        19.5k83854




        19.5k83854






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350012%2ferror-update-username-in-firebase-database-using-ionic-v3%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Ottavio Pratesi

            Tricia Helfer

            15 giugno