如何从离子框架中的输入字段中获取值?

时间:2017-01-02 08:04:01

标签: angular typescript ionic-framework

下面是电子邮件和密码的两个离子标签:

<ion-item>
    <ion-label color="primary" floating>Email id</ion-label>
    <ion-input id = "email" type="email" ></ion-input>
</ion-item>

<ion-item>
    <ion-label color="primary" floating>Password</ion-label>
    <ion-input id = "pass" type="password" ></ion-input>
</ion-item>

如何从字段中获取文本数据并使用typeScript将其分配给angularjs 2中的变量?

2 个答案:

答案 0 :(得分:0)

使用双向绑定:<ion-input id = "pass" type="password" ng-model="pass"></ion-input>

角度:

angular.module('starter', ['ionic'])
.controller('nameofcontroller',function($scope){
 var formPost = {
      "Pass":pass
    };
console.log(formpost);

    $scope.pass=formPost;

答案 1 :(得分:0)

<ion-item>
    <ion-label color="primary" floating>Email id</ion-label>
    <ion-input id = "email" ng-model="user.email" type="email" ></ion-input>
</ion-item>

<ion-item>
    <ion-label color="primary" floating>Password</ion-label>
    <ion-input id = "pass" ng-model="user.password" type="password" ></ion-input>
</ion-item>

添加ng-model

现在在控制器中

angular.module('starter', ['ionic'])
.controller('nameofcontroller',function($scope){

使用..

$scope.user.email; $scope.user.password;

喜欢.. console.log('User is :',$scope.user.email);