Angularjs有多种功能

时间:2017-06-04 21:36:22

标签: angularjs ionic-framework

我有两个按钮:

  • One扫描QR码并返回有效的值。
  • 在同一页面上确认输入值的另一个,但我无法触发第二个功能。

我有2个输入,deviceidcompanyid,以及2个按钮。扫描按钮ng-click通过scanQR调用,第二个按钮通过ng-click调用checkBlanks

确认ID按钮调用函数首先检查空白,然后在输入数据丢失时提醒用户。一旦2个输入有内容,它将通过verifyDetails()调用保存数据。但是我无法运行checkBlanks函数。

HTML代码是: -

    <ion-view title="Settings">
  <ion-content padding="true" class="has-header">
    <form class="list">
      <label class="item item-input" name="deviceid">
        <span class="input-label">Device ID</span>
        <input type="text" placeholder="" ng-model="deviceid">
      </label>
      <label class="item item-input" name="companyid">
        <span class="input-label">Company ID</span>
        <input type="text" placeholder="" ng-model="companyid">
      </label>
    </form>
    <button ng-click="scanQR()" class="button button-positive button-block">Scan QR to Configure</button>
    <button ng-click="checkBlanks()" class="button button-positive button-block">Confirm ID</button>
    <form class="list">
      <ion-toggle toggle-class="toggle-positive" ng-checked="true">Vibrate</ion-toggle>
      <ion-toggle toggle-class="toggle-positive">Light on Scan</ion-toggle>
      <div style="text-align:center;" class="show-list-numbers-and-dots">
        <p style="color:#000000;font-size:10px;">On Android devices set to off and use the volume controls to turn the flashlight on or off.</p>
      </div>
      <ion-radio ng-model="radioCheck" value="security">Security</ion-radio>
      <ion-radio value="utilities">Utilities</ion-radio>
    </form>
  </ion-content>
</ion-view>

AngularJS是: -

function($scope, $stateParams) {
  $scope.radioCheck = "security";
  $scope.scanQR = function() {
    cordova.plugins.barcodeScanner.scan(
      function(result) {
        var TagResponse = result.text;
        var config = TagResponse.indexOf("Config:");
        if (TagResponse !== '') {
          if (config === 0) {
            var ConfigVals = TagResponse.split(':');
            $scope.deviceid = ConfigVals[1];
            $scope.companyid = ConfigVals[2];
            $scope.$apply();
          }
        }
      });
  };
  $scope.checkBlanks = function() {
    alert("Device ID" + $scope.deviceid);
    console.log("Device ID" + $scope.device)
    if ($scope.deviceid === '') {
      alert("Please enter a device ID", Dismissed, "Error");
    } else if ($scope.companyid === '') {
      alert("Please enter a Company ID", Dismissed, "Error");
    } else {
      verifyDetails();
    }
  };
}

任何帮助表示赞赏,我对Angularjs和Ionic都很陌生。

0 个答案:

没有答案