【问题标题】:how to fetch value from input field in ionic framework?如何从离子框架中的输入字段中获取值?
【发布时间】:2017-01-02 08:04:00
【问题描述】:

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

<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 中的变量?

【问题讨论】:

    标签: angular typescript ionic-framework


    【解决方案1】:

    使用双向绑定:&lt;ion-input id = "pass" type="password" ng-model="pass"&gt;&lt;/ion-input&gt;

    角度:

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

    【讨论】:

      【解决方案2】:
      <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);

      【讨论】:

      • console.log('用户是:',$scope.user.email);在控制台中不显示任何内容
      猜你喜欢
      • 2015-09-03
      • 1970-01-01
      • 2015-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多