Get input datas from html to .ts

I have a little problem with my code,
i have to save datas written by the user but i can’t get it.

In this kind of input:

          <ion-label stacked>First Name</ion-label>
          <ion-input type="text" aria-placeholder="First Name" placeholder="First Name" [(ngModel)]="firstName" name="firstName"></ion-input>

And my .ts:

firstName = ' ';
public qObj = {
  firstName: this.firstName,

When the user press the button “SAVE” the variable into the qObj is ’ ’ not the name he wrote…

I don’t know how should i do…

Thanks for your time !

try this one

1 Like

I got an error :
ERROR TypeError: Cannot read property ‘firstName’ of undefined
at Object.eval [as updateDirectives]

One of my general rules is “don’t put the same thing in multiple places”, because doing so leads to bugs like this when they get out of sync. So I would recommend losing either firstName or qObj as an object property.

Do you mean that i have to delete the "public firstName = ’ '; " ?

That’s one option. Another would be making qObj lexically scoped, assuming it needs to exist at all. Just don’t have them both be in the same scope (as object properties of the component).

1 Like

The fact is i’m a beginner in Ionic3 and scopes are a bit strange for me. I don’t even know where put things like:
app.controller(‘myCtrl’, function()) etc…

That would be AngularJS (i.e. Angular 1) syntax, and thus won’t be used in Ionic 3.

Scope in this case refers to JavaScript/TypeScript scope, and not the AngularJS concept of $scope.

1 Like