AngularJS ng-show - sg-hide -ng-click

时间:2015-09-22 12:20:25

标签: javascript angularjs ionic angularjs-ng-click angularjs-ng-show

如何获得单击时隐藏的开始按钮并显示停止按钮。 当我点击停止按钮时,我想看到出现的开始按钮。 我试过这个,但事实并非如此。 有人有想法吗?



'use strict';
angular.module('djoro.controllers')
.controller('WifiSmartConfigCtrl', function($scope, $window, $ionicPlatform){
  $scope.EventRunning = false;
  $scope.showAlert = function(){
    $ionicPlatform.ready(function(){
      $window.cordova.plugins.Smartconfig.alert('My plugin works !');
    });
  };
  $scope.startSmartconfig = function(){
    var onSuccess = function(success){
      $scope.StartEvent = function (event) {
        event.preventDefault();
        $scope.EventRunning = true;
      };
    };
    var onFail = function(){};
    $ionicPlatform.ready(function(){
      $window.cordova.plugins.Smartconfig.startSmartconfig(onSuccess, onFail, wifiPassword);
    });
  };
  $scope.stopSmartconfig = function(){
    $ionicPlatform.ready(function(){
      var onSuccess = function(){
        $scope.StopEvent = function (event) {
          event.preventDefault();
          $scope.EventRunning = true;
        };
        alert("stopSmartconfig done");
      };
      var onFail = function(){};
      $window.cordova.plugins.Smartconfig.stopSmartconfig(onSuccess, onFail);
    });
  };
)};

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>

<div class="startWifi">
                <button ng-hide="EventRunning" class="button button-full button-balanced" ng-click="startSmartconfig($event)">Start</button>
                <button ng-show="EventRunning" class="button button-full button-assertive" ng-click="stopSmartconfig($event)">Stop</button>
</div>
&#13;
&#13;
&#13;

如何获得单击时隐藏的开始按钮并显示停止按钮。 当我点击停止按钮时,我想看到出现的开始按钮。 我试过这个,但事实并非如此。 有人有想法吗?

2 个答案:

答案 0 :(得分:0)

'use strict';

angular.module('djoro.controllers')

 .controller('WifiSmartConfigCtrl', function($scope, $window,    $ionicPlatform){

 $scope.EventRunning = false;

  $scope.showAlert = function(){
 $ionicPlatform.ready(function(){
   $window.cordova.plugins.Smartconfig.alert('My plugin works !');
});
};

$scope.startSmartconfig = function(event){

    var onSuccess = function(success){
        $scope.StartEvent = function (event) {
        event.preventDefault();
        $scope.EventRunning = true;
        };

    };

    var onFail = function(){};

    $ionicPlatform.ready(function(){

    $window.cordova.plugins.Smartconfig.startSmartconfig(onSuccess, onFail, wifiPassword);

    });

 };

 $scope.stopSmartconfig = function(event){
    $ionicPlatform.ready(function(){



      var onSuccess = function(){

        $scope.StopEvent = function (event) {
        event.preventDefault();
        $scope.EventRunning = true;
    };

          alert("stopSmartconfig done");
      };
      var onFail = function(){};

      $window.cordova.plugins.Smartconfig.stopSmartconfig(onSuccess, onFail);
    });



     };

   )};

您的控制器方法您的调用包含一个参数,并且您在方法中没有传递任何参数,请参阅上面的代码

答案 1 :(得分:0)

您关闭了错误的代码,我不知道这是否会解决您的问题,但它可能会产生其他问题,所以如果您还有)};,请更换});问题请检查是否有任何错误。