Using AngularJS to use ng-show, sg-hide, and ng-click

Is there a way to create a Start button that hides when clicked and shows a Stop button instead? When the Stop button is clicked, the Start button should reappear. I've attempted this but it doesn't seem to work. Any suggestions or ideas?

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

Is there a way to create a Start button that hides when clicked and shows a Stop button instead? When the Stop button is clicked, the Start button should reappear. I've attempted this but it doesn't seem to work. Any suggestions or ideas?

Answer №1

'use strict';

angular.module('djoro.controllers')

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

 $scope.IsEventOccurring = false;

  $scope.displayPopup = function(){
 $ionicPlatform.ready(function(){
   $window.cordova.plugins.Smartconfig.alert('My plugin is functioning properly!');
});
};

$scope.initiateSmartConfig = function(event){

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

    };

    var onFail = function(){};

    $ionicPlatform.ready(function(){

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

    });

 };

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



      var onSuccess = function(){

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

          alert("SmartConfig termination successful");
      };
      var onFail = function(){};

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



     };

   )};

The method in your controller requires a parameter, but you are not passing any parameter in the method as shown in the code above.

Answer №2

Your code closing syntax is incorrect. While I'm not sure if this change will solve your issue, using the proper closing syntax is crucial to avoid potential conflicts. Try replacing the current syntax )}; with });. If the problem persists, make sure to thoroughly check for any underlying errors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to create an internal link to another HTML templating engine page within Express.js?

I am currently facing an issue with two Pug files, index.pug and search.pug, stored in a /views folder. In my index.pug file, I have the following line of code: a(href="/search.pug") Search In my JavaScript file, I have specified the view engine as P ...

Use ng-class in a P tag to assess a variety of expressions

Is there a way to apply ng-class to automatically evaluate negative values within a < p > tag? <p <strong>LW$:</strong> {{d.lw_metric}} <strong>LW:</strong> {{d.lw_metric_percentage}} <strong>L4W:</strong> {{ ...

Combine the values of two text fields from separate input fields to populate a new text field across several lines

https://i.sstatic.net/fp8aZ.png I am seeking a way to automatically calculate the total cost by multiplying the quantity and unit cost values for each line entered. Despite my attempts with the jQuery script provided below, I have been unable to achieve t ...

Tips for overriding ng-disable in AngularJSUnleashing the

This is a comment box using AngularJS: <tr> <td colspan="5"><br/>Comments* <div><textarea class="form-control" rows="3" cols="60" ng-model="final_data.drc_scope" placeholder="Add comments here" ng-disabled="is_team==0 || isDis ...

Tips for displaying Vue Components on an HTML5 canvas surface

How can I incorporate an htmlcanvas as the webpage background and overlay Vuejs components on top of it? I know the answer must exist, but I'm not sure where to start looking. ...

jQuery code unable to alter the class of a div

Need help with a script on my single page site that adds a "read more" style link to a content area's div. The goal is for the button to change the class of the content area when clicked, showing all of the content. Clicking again should hide the cont ...

Tips on customizing label colors on a Donutchart using Google API

https://i.sstatic.net/Rpor0.png I am looking to change the color of 12.5 (to Green) and 25 (to red) based on the donut arc color in Google Charts. Below is the code snippet: var container = document.getElementById('chart_div'); var chart = new ...

In React components, encountering "cannot read properties of undefined" error occurs, whereas it functions perfectly fine within the getStaticProps

I am currently in the process of setting up a blog using Node.js, React, and graphql. Despite being new to these technologies, including Java and Typescript, I am seeking assistance from anyone who may be able to help. My current roadblock involves display ...

What is the best way to display a page within a div when clicking in Yii?

I'm trying to use the jQuery function .load() to load a page into a specific div. Here's my code: <a href="" onclick="return false;" id="generalinfo"> <div class="row alert alert-danger"> <h4 class="text-center">Gen ...

Issues with AngularJS version 1.8.0 and the ng-selected option functionality not functioning as

I recently updated the AngularJs version from 1.4.8 to 1.8.0 and encountered an issue with ng-selected on a select element that requires a default value. Can anyone provide guidance on how to set ng-selected in version 1.8.0? (the code utilizes ng-model) ...

Anticipated the presence of a corresponding <div> within the server's HTML nested in another <div>

I've encountered a troubling error on my website while using Next.js. The error is causing layout issues and upon investigation, it seems that the device detection hook is at fault. Here's the hook in question: const isBrowser = typeof window !== ...

How should event listeners be unbound and child elements removed in single page applications?

I've recently delved into the world of memory leaks in JavaScript while working on a large single-page application. After using Chrome's Profiles (Snapshot) function, I noticed an abundance of detached DOM elements indicating a possible memory le ...

Issues with audio and video playback intermittently occurring on Sencha Touch 2

As a beginner with Sencha Touch 2, I am currently working on uploading images onto an iPad using Xcode. My app has audio playing on the home screen, and I want the video to start playing and the audio to stop when a specific tab is selected. However, the ...

Dynamically changing images in Angular based on a value

Below is the code snippet I have written: I am currently using only an if-else condition, but I want to implement an if-elseif-if condition based on three values in order to change the image accordingly. <img [src]="status.getRequestStatus() == ' ...

The process of passing parameter values by function in useEffect

Hi everyone, I hope you're all doing well. I'm currently facing an issue with trying to retrieve data from my API using the post method. The problem is that I can't use useEffect in any parameter. So, my workaround is to pass the data throug ...

Is there a way to completely remove an element from the dom once the ajax call has returned

I've been struggling to completely remove LI elements and their content, including the checkbox input, from the DOM without success. After an ajax callback, I am calling the following function, but it only removes the contents and not the element its ...

Using Bootstrap to present information with a table

Presenting information in a Bootstrap table with Vue.js I have gathered the necessary data and now I want to showcase it in a table using bootstrap. Currently, I have achieved this using SCSS as shown in the image below: https://i.sstatic.net/XN3Y4.png ...

Tips for creating an endless loop within a nested v-for in Vue?

Here is my attempt at solving the problem: HTML <ul class="tree"> <li> <span>First Node</span> <ul> <li v-for="(tree, i) in trees" :key="i"> <span v-text="tree. ...

Choosing a radio button based on the stored value within a variable

When transferring a variable (active) from my route to EJS, I initially found it easy to simply display its value: <!-- Active Text Input--> <div class="form-outline mb-4"> <label for="active" class="form-label">Active</label> ...

Switching between sockets on a rotational basis

Imagine there is a division in the HTML file, and an interesting game is being played where each player has the opportunity to change the color. However, there’s a twist – they can only switch colors after the other player has taken their turn. The pla ...