本文介绍了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

推荐答案

确保在声明 SignInPage 组件的模块上导入 NativescriptFormsModule,而不仅仅是在 AppModule 中.

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

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

08-30 07:00