2016-08-11 5 views
1

Ich möchte die TextField text -Eigenschaft programmatisch mit angular2 Datenbindung aktualisieren. Von here sieht es so aus, als würde ich [(ngModel)] = "email" in meinem Layout setzen und dann in meinem Code eine Eigenschafts-Email hinzufügen. Mit der aktuellen Einstellung kann ich die Texteigenschaft beim Laden ändern. Wenn ich jedoch versuche, die Texteigenschaft programmgesteuert über eine Schaltfläche zu ändern, werden die Änderungen an der E-Mail nicht in der TextField-Texteigenschaft der Ansicht wiedergegeben.NativeScript 2/Angular 2 Datenbindung [(ngModel)] Wie aktualisiere ich TextField programmatisch.

import { Component, OnInit } from '@angular/core'; 
import { User }    from '../../shared/user/user'; 
import { LoginModel }  from '../../model/login/login-model'; 
import { HttpService }  from '../../services/http/http-service'; 

@Component({ 
    selector:'login', 
    templateUrl:'pages/login/login.component.html', 
    providers: [HttpService] 
}) 

export class LoginComponent implements OnInit { 
    email:string = "[email protected]"; 
    user: User; 
    //model: LoginModel; 
    constructor(private _httpService: Httpservice) { 
     //this.model = new LoginModel(); 
     this.user = new User(); 
    } //default constructor 

    ngOnInit() {} 

    onButtonTap() { 
     //alert("onButtonTap clicked "); 
     //this._mpixService.register(this.model.user); 

     this.email = "[email protected]"; 
     alert("onButtonTap clicked " + this.email); 
    } 
} 

Meine Ansicht

<ActionBar title="Login Mpix Tap To Print"> 
    <ActionItem text="Login" android.systemIcon="ic_menu_share_holo_dark" ios.systemIcon="9" ios.position="right"></ActionItem> 
</ActionBar> 
<StackLayout> 
    <TextField hint="Email Address" keyboardType="email" 
     autocorrect="false" autocapitalization="none" [text]="email"></TextField> 
    <TextField hint="Password" secure="true" keyboardType="password" 
     autocorrect="false" autocapitalization="none" [(ngModel)]="password"></TextField> 

    <Button text="Sign In" (Tap)='onButtonTap()'></Button> 
    <Button text="Sign up for Mpix" [nsRouterLink]="['/signup']"></Button> 
</StackLayout> 

ich auch Variationen von TextField- versucht haben, sehen Immobilien

<TextField hint="Email Address" keyboardType="email"  autocorrect="false" autocapitalization="none" [text]="email" (emailChange)="email=$event"></TextField> 

<TextField hint="Email Address" keyboardType="email"  autocorrect="false" autocapitalization="none" [(ngModel)]="email" [text]=email></TextField> 

<TextField hint="Email Address" keyboardType="email"  autocorrect="false" autocapitalization="none" [(ngModel)]="email">{{email}}</TextField> 

Das Textfeld lädt zunächst zu [email protected], wenn die Schnittstelle eingestellt ist.

+0

[(ngModel)] = "E-Mail" text = {{email}}> auch nicht mit dieser Arbeit. – dsum27

Antwort

0

Dieses Problem mit einer aktuellen Update behoben wurde. Es gibt weitere Details unter dem folgenden Link. Im Grunde gab es ein nicht zusammenhängendes Build-Problem, das den Code stoppte, bevor mein Code ausgeführt werden konnte. Nach dem Update von tns-core-modules und nativescript-angular hat es mit dem obigen Code funktioniert.

Nativescript 2.2 exception

8

Sie können auf Einfuhren haben die Formulare Modul aus NativeScript in Ihre NgModule Importe Array:

Import {NativeScriptFormsModule} von "nativescript-Winkel/forms";

und in NgModule Attribute

@NgModule ({Importe: [NativeScriptFormsModule]})

Verwandte Themen