首页 > AngularJS中使用ng-model绑定的input无法取到值

AngularJS中使用ng-model绑定的input无法取到值

index.html:

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.min.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app="login">
<ion-pane>
  <ion-content ng-controller="put">
    <form class="list list-inset">
    
      **//这里的用户名密码并无法取到**
      <label class="item item-input">
        <input type="number" placeholder="用户名" name="user" ng-model="postform.user">
      </label>
      <label class="item item-input">
        <input type="password" placeholder="密码" name="pword" ng-model="postform.pword">
      </label>
      
    </form>
    <div class="padding">
      <button class="button button-block button-positive" ng-click="x();">登录</button>
    </div>
  </ion-content>
</ion-pane> 
</body>
</html>

app.js:

var yep = angular.module('login', ['ionic'], function ($httpProvider) {
  $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

var param = function(obj) {
var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
  
for(name in obj) {
  value = obj[name];
    
  if(value instanceof Array) {
    for(i=0; i<value.length; ++i) {
      subValue = value[i];
      fullSubName = name + '[' + i + ']';
      innerObj = {};
      innerObj[fullSubName] = subValue;
      query += param(innerObj) + '&';
    }
  }
  else if(value instanceof Object) {
    for(subName in value) {
      subValue = value[subName];
      fullSubName = name + '[' + subName + ']';
      innerObj = {};
      innerObj[fullSubName] = subValue;
      query += param(innerObj) + '&';
    }
  }
  else if(value !== undefined && value !== null)
    query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
}
  
return query.length ? query.substr(0, query.length - 1) : query;};
 $httpProvider.defaults.transformRequest = [function(data) {
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
  }];
});

yep.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

  cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}
});
})

yep.controller('put', ['$scope', '$http', function ($scope, $http) {
"use strict";

$scope.postform = $scope;

**//在这里并不能拿到user和pword值**

var datainform = {
    'username': $scope.user,
    'password': $scope.pword,
    'lt': "e2s2",
    '_eventId': "submit",
    'submit': "登录"
}

$scope.x = function () {
    $http({
        url: 'http://gzb.szsy.cn:3000/cas/login?service=http://gzb.szsy.cn/card/Default.aspx',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        method: "POST",
        data: datainform
    }).success(function(data, status, headers, config){
        
    });
  };
}]);

ng-click="x();" 的时候把postform传进去呀。

【热门文章】
【热门文章】