2

我的 html 中有一个 div

<div class="row" ng-show="loginCtrl.showTouchID" >
    <div class="col-xs-12">
                    <button type="button" class="col-xs-12 btn btn-touch-id" data-ng-click="#">
                        TouchID Login
                    </button>
                </div>
            </div>

现在需要在我的控制器构造器中检查设备是否支持触摸 ID(如果显示 div)

  window.plugins.touchid.isAvailable(
            function (msg) {
                navigator.notification.alert('Touch id  supported: ' + msg);
                loginCtrl.showTouchID=true;


            }, function (msg) {
                navigator.notification.alert('Touch id not supported: ' + msg);
                loginCtrl.showTouchID=false;

            });

但这不起作用,任何人都可以纠正我

在我的登录控制器下方

  angular.module('heritage').controller('LoginCtrl', LoginCtrl);
    LoginCtrl.$inject = ['$scope','$rootScope', '$state', '$window', 'UserService', 'ServiceHelper', '$stateParams'];

    /**
     * Construct the controller.
     * @param $rootScope the root scope
     * @param $state the state object
     * @param $window the window object
     * @param UserService the user service
     * @returns the controller object
     */
    function LoginCtrl($scope,$rootScope, $state, $window, UserService, ServiceHelper, $stateParams) {
4

2 回答 2

2

将 传递$scope给您的函数(如果它是外部的)并$scope在那里更改变量。

  window.plugins.touchid.isAvailable($scope
            function (msg) {
                navigator.notification.alert('Touch id  supported: ' + msg);
                $scope.showTouchID=true;


            }, function (msg) {
                navigator.notification.alert('Touch id not supported: ' + msg);
                $scope.showTouchID=false;

            });
于 2015-11-24T06:24:40.590 回答
2

这是一个有效的JSFiddle

HTML:

<div ng-app="app" ng-controller="dummy">
    <div class="row" ng-show="loginCtrl.showTouchID">
        <div class="col-xs-12">
            <button type="button" class="col-xs-12 btn btn-touch-id" data-ng-click="setTouch('hello')">TouchID Login</button>
        </div>
        <p>{{loginCtrl.showTouchID}}</p>
    </div>
</div>

JS:

var app = angular.module("app", []);
app.controller('dummy', function ($scope) {
    $scope.loginCtrl = {showTouchID: true};

    $scope.setTouch = function (msg) {
        if ($scope.loginCtrl.showTouchID) {
            alert('Touch id not supported: ' + msg);
            $scope.loginCtrl.showTouchID = false;
        } else {
            alert('Touch id supported: ' + msg);
            $scope.loginCtrl.showTouchID = true;
        }
    }
});
于 2015-11-24T07:15:55.273 回答