Start variables with data from an Input

0

I am developing an App in Ionic ... in a module I am showing data from the database. These data bring an id, said id I'm placing it in a for later in my controller recover that id, and make actions on that record. The problem starts here, in my controller I declared an array such that FixName: any [] = [] . Inside the constructor I defined two index of the controller nameArray ['index1'] = '' .

In my view I defined an Input in which I assign (As I had already said the id of a record).

When I access the view, it gives me an error, the error is because my fix in the constructor is defining it as empty, and in the view I am defining that arrangement with a data.

[

    
asked by Elias Galarza 10.11.2017 в 22:18
source

2 answers

0

Thanks for your answers ... I add my code as an example

MY CONTROLLER

survey: any [] = [];

constructor (public navCtrl: NavController,               public navParams: NavParams,               public userService: UserProvider,               public toastCtrl: ToastController,               public http: Http,) {

this.http; Http;

this.encuesta['idencuesta'] = '';

this.http.get(url).subscribe(data =>{
  //console.log(data.json())
  this.lists = data.json();//Esto es de otro arreglo :d
  console.log(this.lists['registros']);//Esto es de otro arreglo :d

}, error=> {
  console.log(error.json());
});

}

voteYes () {

let data = new URLSearchParams();

data.append('encuesta[idCiudadano]', this.encuesta['idCiudadano']);
data.append('encuesta[idencuesta]', this.encuesta['idencuesta']);

  this.http.post(url, data)
   .subscribe(data =>{
   },error =>{
     console.log(error.json());
   })

}

VISTA   

In the view Basically, I put an input with the id of a survey, to know which poll is going to vote. In the Controller with the Append I recover that data (idencuesta) that is going away to vote. It is there, where the error jumps .. that the variable is initialized as empty and in the input it is defined with a value.

    
answered by 11.11.2017 / 20:26
source
0

I more or less understood your question, you should document it a bit more to be able to understand you

What I understood is that you want to define an array and then fill it with even data so you should define the array with all fields (just before the constructor)

something like that

  public Form = {
        campo1:"",
        campo2:"",
        campo3:"",
        campo4:"",
        
   };

If you are going to fill the array with data in the constructor you should use

this.Form.campo1 = "El valor que le quiero asignar ";

if you want to fill them in from an input

<ion-item>
          <ion-label color="primary">campo1 </ion-label>
          <ion-input placeholder="escriba el valor" name="campo1" [(ngModel)]="Form.campo1" ></ion-input>
</ion-item>
    
answered by 10.11.2017 в 22:50