javascript 如何使用 Ionic 返回文本框的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27252454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 07:12:59  来源:igfitidea点击:

How to return the value of textbox using Ionic?

javascriptangularjsionic-framework

提问by sharataka

I have a form in Ionic and I am trying to return the value of the textbox, but am having issues. The rest of the form is loading and 'signup' is returned to the console. formData.email isn't bound in the template and neither is anything returned to the console when I type something in and click the button.

我有一个 Ionic 表单,我试图返回文本框的值,但遇到了问题。表单的其余部分正在加载,并且“注册”返回到控制台。formData.email 未绑定在模板中,当我输入内容并单击按钮时,也没有任何内容返回到控制台。

Any advice on what to do?

关于该怎么做的任何建议?

signup.html

注册.html

<!-- Header -->
<div class="bar bar-header bar-light">

  <button class="button icon-left ion-chevron-left button-clear button-dark">Back</button>

  <h1 class="title">Signup</h1>
</div>

<!-- Space between header and signup form -->
<div class="spacer" style="width: 300px; height: 50px;"></div>


<div class="list list-inset">

    <!-- Signup form text fields -->
    <form>

        <label class="item item-input">
            <span class="input-label">Email</span>
            <input type="email" ng-model="formData.email">
        </label>



        <label class="item item-input">
        <span class="input-label">Username</span>
        <input type="text">
        </label>

        <label class="item item-input">
        <span class="input-label">Password</span>
        <input type="password">
        </label>

        <!-- Submit button for signup form -->
        <button on-touch="onTouch()" class="button button-positive button-block">
            Sign up
        </button>

    </form>
</div>

{{formData.email}}

controllers.js

控制器.js

.controller('SignupCtrl', function($scope, $ionicLoading, $state, $stateParams){
    console.log('signup');

    $scope.formData = {};

    //Go to the guessing page
    $scope.onTouch = function(item,event){
        console.log($scope.formData.email);
    };



});

采纳答案by Sha Alibhai

What you're doing is correct, the only thing that I could do to recreate this was if you haven't entered a valid email address it returns undefined. This is a validation feature built in to Angular itself and has nothing to do with Ionic. You can find out more about this here: https://docs.angularjs.org/api/ng/input/input%5Bemail%5D

你所做的是正确的,我唯一能做的就是重新创建这个,如果你没有输入一个有效的电子邮件地址,它会返回未定义。这是一个内置于 Angular 本身的验证功能,与 Ionic 无关。您可以在此处找到更多相关信息:https: //docs.angularjs.org/api/ng/input/input%5Bemail%5D