0

I am working in angularjs and am new to it, I have made an app using this.

There are a few pages in my app, now my problem is i am having two buttons which navigate to other pages, but my issue is when i click on a button (span), it opens the same page twice.

Can anyone please help me how to solve this? My code is as below:

javascript

  $scope.foo = function() {
        if ($scope.filterflg !== "1" ) {
            $scope.filterflg = "1";
             $scope.disabled = true;


            gallery.pushPage("filter.html", {
                params: FkCategory
            });

            $timeout(function() {
                console.log("====timeout occured===");
                $scope.filterflg = "0";
                  $scope.disabled = false;
            }, 3000);
        }
    };

html

<ons-button  id="test1" class="toolbar-button--quiet navigation-bar__line-height"  ng-click="isProcessing=true;foo()" ng-model ="filterflg"
         style="border: none; padding: 0 5px 0 0; margin-right:7px ;">
            <i class="ion-android-options" style="font-size:24px; color: #FFFFFF;"></i>
        </ons-button>

I have wasted 10 days on this issue, hope some buddy will help me to save my job..! :(

Barm
  • 403
  • 5
  • 11
JIGAR
  • 302
  • 2
  • 15

3 Answers3

3

ng-disabled doesn't work on span. It only works for input or button types.

you have two options -

  1. convert the span to a button element

  2. use a variable like $scope.isProcessing to wrap the foo() function.

    $scope.foo = function() {

    if (!$scope.isProcessing) {     
        //...       
        $timeout(function() {
             console.log("====timeout occured===");
             $scope.filterflg = "0";
             $scope.disabled = false;
             $scope.isProcessing = false;        
        }, 3000);
     }
    

    };

html

<span ng-click="isProcessing=true;foo()"></span>
Rabi
  • 2,210
  • 17
  • 18
1

convert the span to a button element and disable that button without $timeout just after first click

 $scope.foo = function() {
        just simply 
        $scope.disabled = false;
        // Your other code 


 };

or use a flag to check page is already open or not will solve your problem

 $scope.isFilteropen = false;

 $scope.foo = function() {
     if ($scope.isFilteropen == false) {
         $scope.isFilteropen = true;
        // your other code 
     }
 };
Shailendra Sharma
  • 6,976
  • 2
  • 28
  • 48
  • And what changes in my html? – JIGAR Nov 19 '15 at 09:06
  • could you create a fiddle with your problem , my solution works fine check it here http://jsfiddle.net/HB7LU/20051/ – Shailendra Sharma Nov 19 '15 at 09:26
  • Hello brother,you did what i exactly want but can we re enable when we come back to that page from page stack as its an app – JIGAR Nov 19 '15 at 09:42
  • yes i know button re enable automatically when we back on page, because when we back on page controller also recalled and $scope.disabled = false; make button re enable – Shailendra Sharma Nov 19 '15 at 09:50
  • actually i am using onsen ui for this app,and which maintaing a page stack in anvigator,so when we come back no controller is calling..got my point? – JIGAR Nov 19 '15 at 10:10
  • Than simple timeout work look at this http://jsfiddle.net/HB7LU/20054/ but i am not aware of onsen ui that's why i ask you for a fiddle – Shailendra Sharma Nov 19 '15 at 10:25
  • thank you sharma ji ... :) can you please help me on one more question,its also weird..! – JIGAR Nov 19 '15 at 11:24
  • Have you ever used Onsen ui?if yes then you know it provide a default back button and its navigator maintains a page stack,Now my problem is when i click more than one time it says "pagestack is empty" and my app stopped working..it only happens when i click very fast and twice on back button.can you suggest any solution for this. – JIGAR Nov 19 '15 at 12:13
0

Try this one,

<span class="toolbar-button--quiet navigation-bar__line-height" ng-disabled="disabled" ng-click="disabled=true;foo();disabled=false;" ng-model ="filterflg"> </span>

And remove your timer from the function Foo().

Abhilash Augustine
  • 4,128
  • 1
  • 24
  • 24