Having issues with the functionality of AngularJS ng-show

I am trying to dynamically show and hide a button using the ng-show directive.

Below is the HTML code I have written:

<button class="btn btn-info" ng-show="editBtn">Save Edit
        <span class="glyphicon glyphicon-ok"></span>
    </button>

And here is the controllerScript code for my AngularJS app:

    myApp = angular.module("myApp", []);

myApp.controller ("epmloyeeCtrl", ["$scope", function($scope){
  $scope.editBtn = false;
}]);

Answer №1

It appears that you may have overlooked adding either ng-app or ng-controller in your HTML code. Ensure it is included like this:

<div ng-app="myApp">
   <div ng-controller="epmloyeeCtrl">
     <button class="btn btn-info" ng-show="editBtn">Save Edit
        <span class="glyphicon glyphicon-ok"></span>
      </button>
   </div>
</div>

Controller:

var myApp = angular.module("myApp", []);
myApp.controller ("epmloyeeCtrl", ["$scope", function($scope){
  $scope.editBtn = false;
}]);

I have created a demo showcasing the functionality of the Show/Hide Edit Button from your code: Here!

Answer №2

Take a look at this Plunker: http://plnkr.co/edit/abc123XYZ?preview

It appears that there is an oversight in updating the state of $scope.editBtn when the edit button is clicked. In the controller's editEmployee function, make sure to include:

$scope.editBtn = true;

In addition, I introduced a variable saveBtn to hide while the user is in editing mode. Also, a cancel button has been added for functionality. You can view these 3 elements on the plnkr provided.

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

When implementing ReplaySubject in Angular for a PUT request, the issue of data loss arises

I seem to be encountering a problem with the ReplaySubject. I can't quite pinpoint what I've done wrong, but the issue is that whenever I make a change and save it in the backend, the ReplaySubject fetches new data but fails to display it on the ...

Modify the website link for the ajax request

I have been successfully fetching data from a URL link using curl, but I have encountered an issue. The response data includes ajax calls that are using my server domain instead of the original path where the files are located. For example: /ajax/fetch.ph ...

Incorporating list updates in Angular

I am brand new to angular and currently working on adding functionality to a list. I have a couple of queries. Why does the console.log output for $scope.newChat show as undefined? Is newChat accessible to the sendChat() function due to variable hoistin ...

Creating an array with user-selected objects in IONIC 3

I've been attempting to separate the selected array provided by the user, but unfortunately, I'm having trouble isolating the individual elements. They are all just jumbled together. My goal is to organize it in a format similar to the image lin ...

Decorating AngularJS' ExceptionHandler with TypeScript is not feasible because a function is not identified as such

Scenario: In the project I am currently involved in, there has been a transition from utilizing AngularJS (1.6.2) with JavaScript to TypeScript 2.1.5. We had implemented a decorator on the $exceptionHandler service which would trigger a call to a common ...

Implementing Materialize CSS functionality for deleting chips

I've been attempting to extract the tag of a deleted chip from the div within the Materialize chips class, but I'm hitting roadblocks. My failed attempts so far: $('.chips').on('chip.delete', function(e, chip){ console.lo ...

Where can the .bowerrc file be found within the project directory?

While going through the angular tutorial, I noticed a mention of the .bowerrc file. However, in my case, this file seems to be missing from myapp directory. I have searched but couldn't find it anywhere. ...

Bootstrap version 4.1 introduces a new feature that allows the collapse menu to automatically close when clicking outside of the div

I'm currently working on creating a plug and play Mega-Menu using the collapse method which has proven to be quite effective so far. However, I'm facing an issue with closing the collapsed item when clicking outside the menu. As a beginner in Ja ...

Using Javascript to Discover and Add Elements to an Array

I am facing a challenge with a dataset retrieved from an AJAX call, which contains a list of users and their roles in connection to the project. Some users can have multiple roles, leading to their presence in the result set in different instances. I am ...

Saving extra parameters with MongooseJS

When saving data in my app using a POST query, how can I include additional parameters to the Item? For example, I would like to add user: req.user._id. var Item = new Model(req.body); Item.save(function (err, model) { res.send(model); }); ...

The conundrum of nested function wrapping in Typescript and its impact on

Upon calling the following function, it returns a Promise<boolean>: const fnc = (i:number) : Promise<boolean> => Promise.resolve(true) // Promise<boolean> const res1 = errorHandler(errorPredicates.sdkError1, fnc, null, 4); However, ...

Is JavaScript necessary for the ASP.NET OnClick attribute?

Take this scenario, for instance: <asp:Button id="Button1" Text="Click here for greeting..." OnClick="GreetingBtn_Click" runat="server"/> Therefore, I pose these inquiries: Is the OnClick attribute ...

retrieve image source based on z-index

I found a way to retrieve the z-index value using this code snippet: findHighestZIndex('div'); function findHighestZIndex(elem) { var elems = document.getElementsByTagName(elem); var highest = 0; for (var i = 0; i < elems.length; ...

React ES6 SystemJS encountered an unforeseen token error that couldn't be caught

Even though I have imported react and react-dom using the System.config setup below, I am still encountering the error mentioned here: Uncaught (in promise) Error: Unexpected token <(…) Here is the HTML structure: <!DOCTYPE html> <html l ...

Trouble with Firebase/Firestore documentation queries in JavaScript

Having trouble using the new Firestore system. I'm trying to retrieve a Collection of all users and go through it, but I can't seem to make it work. db.collection("users").get().then(function(querySnapshot){ console.log(querySnapshot.dat ...

Retrieve items with identical ids, all in a single representation

I have an array filled with objects. My goal is to identify and return the objects with unique IDs, avoiding any duplicates. For example: let arr1 = [ {id: 1, name: 'A'}, {id: 3, name: 'C'}, {id: 1, name: 'A'}, {id: 2, name: ...

Combine API calls using promises

The functionality of a plugin I'm using is currently not functioning as expected, leading me to merge two separate requests. Below is the code I am utilizing: Although I am able to receive a response, I am facing difficulties in checking for response ...

Selenium is having trouble finding an element on the PayPal login page

I am currently facing an issue with automating the PayPal login page using a page object. Despite my efforts, I am unable to click on the Log In button on the page. Here is how the PayPal login page looks: https://i.sstatic.net/9RdvO.png This is my curr ...

Using Node.js to establish communication between HTML and Express for exchanging data

I am faced with a challenge involving two pages, admin.hbs and gallery.hbs. The goal is to display the gallery page upon clicking a button on the admin page. The strategy involves extracting the ID of the div containing the button on the admin page using J ...

Tips for saving data obtained from an ajax call

My jquery ajax function has a callback that creates an array from retrieved json data. Here's an example: success: function (response) { callback(response); }, The callback function, in this case createQuestionsArray(), populates ...