0
Use Ionic 2, I need ngmodel to have a value of a class variable, but error when placing in view, follow my code: viiew
<ion-navbar *navbar>
<ion-title>
POSimplex
</ion-title>
</ion-navbar>
<ion-content class="home" padding>
<button ion-button full (click) = "teste()">Login</button>
<p>
<button ion-button full (click) = "addInput()">Criar conta</button>
</p>
<ion-list>
<ion-item *ngFor="let item of inputs">
<ion-label fixed>{{item.title}}</ion-label>
<ion-input type="{{item.type}}" value="{{item.value}}" [(ngModel)] = "{{item.model}}"></ion-input>
</ion-item>
</ion-list>
</ion-content>
ts :
import {Component} from "@angular/core";
import {NavController, Alert} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
inputs: Array<{title: string, type: string, value: any, model: string}>;
inputsList: Array<Array<{title: string}>>;
sl:string
constructor(private navController: NavController) {
this.inputsList = [];
this.inputs = [
{title: 'User Name', type: 'text', value: 'Fulano de tal', model: 'sl'},
{title: 'Price', type: 'text', value: 500, model: 'sl'}
];
}
addInput() {
//this.inputs.push({ title: "teste", type: "text", value: "valor" });
}
teste() {
let alert = Alert.create({
title:'teste',
message:'msg'+this.sl
});
this.navController.present(alert)
}
}
Console error : browser_adapter.js:77EXCEPTION: Error: Uncaught (in Promise): Template parse errors: Parser Error: Got Interpolation ({}}) Where Expression was expected at column 0 in [{{item.model}}] in Homepage@17:67 ("Fixed>{{item.title}} ][(ngModel)] = "{item.model}}"> "): Homepage@17:67 Parser Error: Got Interpolation ({}}) Where Expression was expected at column 0 in [{{item.model}}=$Event] in Homepage@17:67 ("Fixed>{{item.title}} ][(ngModel)] = "{item.model}}"> "): Homepage@17:67
How can I solve ?
What’s the mistake, son?
– Jéf Bueno
does not display anything in Alert, nor on screen
– Augusto Furlan
porem da erro ao colocar na view, segue meu code
What’s the mistake?– Jéf Bueno
does not display anything in the view
– Augusto Furlan
vc needs to import ngmodel into its parent module. import { Ngmodule } from '@angular/core';
– Joannis