2

I have a div in my html like

<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>

Now need to check in my controller contructor that whether the device support touch id if it is show the div or else not

  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;

            });

But this doesnt work well,Can anyone correct me

Below my login controller

  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) {
5
  • 1
    Make sure that this div is within the ng-controller element. Also, use $scope.loginCtrl.showTouchID instead of loginCtrl.showTouchID to access this variable in the view. Share the loginCtrl code also. It is not clear whether you are using $scope or not anywhere. Commented Nov 24, 2015 at 6:19
  • doesnt woked i have updated my question, the alerts are invoked but no change in div Commented Nov 24, 2015 at 6:28
  • Can you set up a demo fiddle? Commented Nov 24, 2015 at 6:34
  • Seems as u told above the issue with scope only i can hide/show div by setting loginCtrl.showTouchID=false; outside window.plugins.touchid.isAvailable methode but inside this not working Commented Nov 24, 2015 at 7:11
  • How could i access hideTouchId inside the window.plugins.touchid.isAvailable method? i tried using $scope.loginCtrl.hideTouchId=true; Commented Nov 24, 2015 at 7:15

2 Answers 2

2

Here is a working 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;
        }
    }
});
Sign up to request clarification or add additional context in comments.

7 Comments

How could i access hideTouchId inside the window.plugins.touchid.isAvailable method? i tried using $scope.loginCtrl.hideTouchId=true; but doesnt work
inject $window in the controller and use it as $window.plugins.touchid.isAvailable
$window.plugins.touchid.isAvailable this method is working fine please look my controller i have inject $window in the controller and inside the alerts are fired also but $scope.loginCtrl.showTouchID = true; doesnt make any changes to my dom
But if i put loginCtrl.showTouchID outside the method for testing working seems that is not accessible inside that method how can i fix this
Did you define $scope.loginCtrl = {}?
|
2

Pass the $scope to your function (if it is external) and change $scope variables there.

  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;

            });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.