表单输入不与Angular变量绑定

时间:2016-11-22 19:44:34

标签: javascript html angularjs ionic-framework

我正在尝试通过Angular自动发送表单,并将输入值与控制器中的变量绑定。但是出于某些原因,这些值无法识别。

<ion-view cache-view="false" ng-controller="CashierController as cashCtrl" class="background">
  <ion-nav-title></ion-nav-title>

  <ion-content padding="true">

    <form id="cashier" name="cashCtrl.cashierForm" method="POST" action="https://url.action" target="screen">
      <input type='hidden' id='token' name='token' ng-model="cashCtrl.token" />
      <input type='hidden' id='merchantId' name='merchantId' ng-model="cashCtrl.merchantId" />
      <input type='hidden' id='customerId' name='customerId' ng-model="cashCtrl.customerId" />
      <input type='hidden' id='action' name='action' ng-model="cashCtrl.action" />
      <input type='hidden' id='paysolName' name='paysolName' ng-model="cashCtrl.paysolName" />
    </form>

    <iframe name="screen" height=600 width=320>
    </iframe>

  </ion-content>
</ion-view>

现在,在控制器上我按如下方式指定它们:

var app = angular.module('app');

app.controller('CashierController', function($scope, $state, $window, $localStorage, GatewayService) {

  var self = this;

  this.cashierUrl = "https://url.action";
  this.token = $localStorage.cashierToken;
  this.merchantId = '//';
  this.customerId = $localStorage.customerId;
  this.action = '//';
  this.paysolName = 'CreditDebitCards';

  console.log(this.cashierForm);

  document.getElementById('cashier').submit();

  this.goToPage = function(page) {
    $state.go(page);
  }

})

值得注意的是,如果我使用花括号表示法指定变量,如下所示:{{cashCtrl.token}}但不在表单上,​​绑定值会显示。此外,第console.log(this.cashierForm);行返回undefined

我做错了什么?

0 个答案:

没有答案