如何获取离子的输入文本值 [英] How to get input text value in ionic

查看:77
本文介绍了如何获取离子的输入文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取input文本值并将其存储在ionic中名为input的变量中.但是我尝试并失败了.谁能告诉我我做错了什么?

I'm trying to get input text value and store it in a variable named input in ionic. But I tried and failed. Can anyone please tell me what I have faulty done?

这是我的HTML

  <ion-content>
  <ion-list>
    <ion-item> 
        <ion-label stacked>display</ion-label>
      <ion-input type="text" text-right id="input" ></ion-input>
    </ion-item>    
  </ion-list>
  </ion-content>

这是我的离子性home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {
    var input=document.getElementById('input').nodeValue;
    document.getElementById('seven').innerHTML=input;
  }

}

有人可以帮助我吗?

推荐答案

实际上,您似乎是在使用angular而不是angularjs,请使用[[ngModel)]

Actually you seems to be using angular not angularjs, use [(ngModel)]

 <ion-input type="text" [(ngModel)]="name" text-right id="input" ></ion-input>

和组件内部

name:string;

name:string;

因此,只要需要该值,就可以使用.

so whenever you need the value , you can use.

console.log(this.name);

console.log(this.name);

这篇关于如何获取离子的输入文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆