首页 文章

ngModel无法在Nativescript中工作

提问于
浏览
0

我最近在Nativescript游乐场上开发了一个简单的应用程序,在那里我发现ngModel不能处理输入类型的TextField . 我已经确保我在应用程序的模块中导入NativescriptFormModule . 但它仍然无法正常工作 .

1 回答

  • 0

    您使用扩展语法而不是ngModel( texttextChange ),因为TextFuield是具有多个可绑定属性(提示,文本,返回类型等)的复杂布局 - 示例Playground here和文档文章here

    HTML

    <TextField [hint]="hint" [text]="name" (textChange)="onTextChange($event)"></TextField>
    

    打字稿

    export class SignupComponent implements OnInit {
        name: string;
        hint: string = "enter name";
    
        tf: TextField;
    
        onTextChange(args: EventData) { 
            console.log("onTextChange");
    
            this.tf = <TextField>args.object;
            console.log("tf.text: ", this.tf.text);
        }
    }
    

相关问题