本文介绍了NativeScript ng2双向绑定在TextField上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作移动应用.在我的登录表单中,我有2个TextFields

im making a mobile app. In my login form i have 2 TextFields

<TextField hint="Email Address" keyboardType="email" [(ngModel)]="email" autocorrect="false" autocapitalizationType="none"></TextField>
<TextField hint="Password" secure="true" [(ngModel)]="password"></TextField>
 <Label [text]="email"></Label>

在component.ts

in component.ts

import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { Page } from "ui/page";
import * as Toast from 'nativescript-toast';
@Component({
    moduleId: module.id,
    selector: 'sign-in',
    templateUrl: "template.html"
})
export class SignInPage implements OnInit {
    email: string ="example";
    password: string;
    constructor(private router: Router, page: Page) {
        page.actionBarHidden = true;
    }
    ngOnInit() {

        var loginParams = { user: { email: this.email }, password: this.password };

        console.dump(loginParams);
    }
}

标签显示示例",但textField不显示.更改textField的值不会更改组件逻辑中的值.任何的想法?

Label is showing "example" but textField does not. Change value of textField doesnt change value in component logic.Any Idea?

ps.我已经在@ngModule中导入了NativescriptFormsModule

ps. I already imported NativescriptFormsModule in my @ngModule

推荐答案

请确保您不仅在AppModule中在声明SignInPage Component的模块上导入NativescriptFormsModule.

Make sure you import NativescriptFormsModule on the module that declare SignInPage Component not only in AppModule.

这篇关于NativeScript ng2双向绑定在TextField上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:00