ng-if not functioning properly following the activation of the "Save Changes" button

When I click the edit change button, I am updating information and then hiding the form to show the updated details by clicking on the Save Changes button. My API successfully updates the information, but for some reason, ng-if does not seem to work after clicking the Save Changes button.

info.html file

<div class="panel-body" ng-if="userEnteredInfo">
    <div class="form-group">
        <dl class="dl-horizontal form-info-table">
            <dt>First Name:</dt>
            <dd>{{user.basicInfo.firstName}}
            </dd>
            <dt>Last Name:</dt>
            <dd>{{user.basicInfo.lastName}}</dd>
            <dt>Status:</dt>
            <dd>{{user.basicInfo.status}}</dd>
            <dt>Work Location:</dt>
            <dd>{{user.basicInfo.workLocation}}</dd>               
            <dt>Date of Birth:</dt>
            <dd>{{user.basicInfo.dateOfBirth}}</dd>
            <dt>Title:</dt>
            <dd>{{user.basicInfo.title}}</dd>
        </dl>
    </div>
</div>
<div class="panel-body form-panel-box" ng-if="makeChanges" ng-submit="saveChanges(user)">
    <form class="form-horizontal edit-changes-form">
        <div class="form-group">
            <label class="control-label col-sm-2" for="firstName">First Name:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="firstName" ng-model="user.basicInfo.firstName">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="lastName">Last Name:
              </label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="lastName" ng-
                 model="user.basicInfo.lastName"> 
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="status">Status:
               </label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="status" ng-
                   model="user.basicInfo.status">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="Work Location">Work 
               Location:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="work" ng-
                  model="user.basicInfo.location">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="dateOfBirth">Date of 
              Birth</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="dateOfBirth" ng-
                  model="user.basicInfo.dateOfBirth">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2" for="title">Title:</label>
            <div class="col-sm-3">
                <input type="text/number" class="form-control" id="title" 
                  ng-model="user.basicInfo.title">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-3">
                <button type="submit" class="btn btn-default">Save 
                 Changes</button>
            </div>
        </div>
    </form>

info.js file

app.controller('info',function($scope,$localStorage,authService,$http){
      $scope.user = $localStorage.userObject;

      $scope.userEnteredInfo = true;
      $scope.editChanges = function(){
        $scope.makeChanges = true;
        $scope.userEnteredInfo= false;

    }
    //Edit changes for updating information//
    $scope.saveChanges = function(userData){
        $scope.updatedInfoDetails = {
            firstName: userData.basicInfo.firstName,
            lastName: userData.basicInfo.lastName,
            status: userData.basicInfo.status,
            WorkLocation: userData.basicInfo.location,
            dateOfBirth: userData.basicInfo.dateOfBirth,
            title: userData.basicInfo.title
        }

    authService.postUpdatedInfo($scope.updatedInfoDetails)
    .then(function(response){
        if(response.status == 200){
             $scope.updatedInfo = "You have successfully updated the changes";

            };
        });
        $scope.userEnteredInfo = false;
        $scope.makeChanges = true;
        console.log("success");

    };
});

authService.js file

app.service('authService', function($localStorage,$http) {
    this.postUpdatedInfo = function(userChangedInfo){
        console.log('the user data is: ', userChangedInfo);
        var urlForChangingInfo = "/api/users/" + $localStorage.getUserId;
        return $http({
            method:'PUT',
            url:urlForChangingInfo,
            data:userChangedInfo,
            headers:{"x-access-token":$localStorage.authToken}
        });
    };    
});

Answer №1

never set makeChanges to false,

give this a go,

calling the authService's postUpdatedInfo function with $scope.updatedInfoDetails parameter
.then checking if the response status is 200:
if so, setting $scope.updatedInfo variable to "You have successfully updated the changes"
setting $scope.userEnteredInfo and $scope.makeChanges to false
logging "success"

Answer №2

you need to make sure that $scope.userEnteredInfo is properly set to true. Here is a suggestion of how you can update the code:

authService.postUpdatedInfo($scope.updatedInfoDetails)
.then(function(response){
    if(response.status == 200){
         $scope.updatedInfo = "Changes have been successfully updated";
         $scope.userEnteredInfo = true;//ensure it's set to true here
         $scope.makeChanges = true;
         console.log("success");
        }
        else
        {
         // handle errors if response status is not 200
         $scope.userEnteredInfo = false;
         $scope.makeChanges = false;
         console.log("error");
        };
    });


};

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

Issue: The system is unable to locate the module labeled './lib/binding/napi-v3/argon2.node'

After attempting to install bcrypt or argon2 with the command npm install --ignore-scripts --omit=dev, an error occurred: app-1 | node:internal/modules/cjs/loader:998 app-1 | throw err; app-1 | ^ app-1 | app-1 | Error: Cannot find modul ...

How can we integrate Cordova plugins into Vue-Cordova framework?

Looking to integrate Vue-Cordova with Cordova-plugin-file-opener2 to open PDF files within iOS/Android applications. In the Vue-Cordova setup, plugins related to the device are defined on the data property of the App vue instance: data: function () { ...

Error message "Exceeded the maximum call stack size" encountered during Vue-router authentication

I am currently in the process of developing a dashboard using Vue, Vuex, and Quasar. However, I have encountered an authentication error that is preventing me from progressing. Additionally, I need assistance in ensuring that when a user is already logged ...

Does SameSite=Lax grant permission for GET requests from third-party sources?

After exploring the MDN documentation on SameSite=Lax, I have come to understand the following: In modern browsers, cookies can be sent along with GET requests initiated by a third-party website or during top-level navigations. This is the default behav ...

Using JQuery and Javascript to retrieve information from one drop down list based on the selection made in another drop down

I'm currently working on a project that involves 2 drop-down menus. The first menu allows you to select a general model, while the second menu displays specific models based on your selection. http://jsfiddle.net/QskM9/ Here's an example of how ...

Icons in Semantic-UI: Facing Difficulty in Accessing ("CORS Request Not HTTP"

Here's an example I'm working on: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Understanding - Main</title> <link rel="stylesheet" type="text/css" href="../semantic/dist/semanti ...

AngularJS does not refresh the view

Currently encountering an issue with data display. Form submission and database update function correctly (backend is operational). However, upon returning to the homepage using a button on the page, The homepage view does not reflect updated values. It ...

A step-by-step guide on signing up users with django-rest-framework and angularJS

Working on a project to create a single page web app using AngularJS and Django. I've decided that all communication between the front and back end should be done through Django-REST. Currently focusing on user registration, but struggling with figu ...

What is it about Next JS and React JS applications that causes them to use up so much cache?

"What causes Next.js and React.js applications to need a large cache, and how does this affect their performance and resource usage?" Refreshing constantly for even small changes in the application as a developer can be frustrating. Are there an ...

The transitionend event fails to trigger if there is no active transition taking place

Take a look at this: http://jsfiddle.net/jqs4yy0p/ JS $('div').addClass('switch').on('transitionend', function(e){ alert('end'); }); CSS div { background-color: red; /*transition: background-colo ...

Using ReactJS to create different behavior for checkboxes and rows in tables with Material-UI

I am looking to customize the functionality of checkboxes and table rows. Currently, clicking on a row also clicks the checkbox, and vice versa. What I would like to achieve is for clicking on a row to trigger a dialogue box, and for clicking on the chec ...

Using AngularJS ng-model to select options in a dropdown menu with WebDriver

In the following code snippet, an AngularJS based dropdown menu is implemented: <select _ngcontent-c1="" class="form-control ng-pristine ng-valid ng-touched"> After opening the list, I attempted to select a variable from this list using the code be ...

What steps can be taken to restrict access to my public REST API so only my single-page application (

My website, housed at my-example-domain.com, utilizes an Angular-based SPA along with a Laravel 5.3 REST API located at my-example-domain.com/api. All of the APIs are accessible to the public, allowing unauthenticated users to interact with my Angular SPA ...

The replacement of className in inline SVG is not permitted (Error: 'Cannot read property 'className.replace' of undefined')

I've hit a roadblock trying to manipulate classes within an SVG document to modify the rect elements. The code works smoothly on divs in an external document, but I've tried several other solutions as well – all listed below. I'm still rel ...

Error: Unable to retrieve the name property of an undefined object within a React component that is being used as a child component within another parent component

FundraiserScreen.js // Import necessary components and dependencies; // Import Fundraiser component; const Children = ({ loading, error, fundraiserData }) => { if (loading) // Show skeleton loading HTML if (!error) return <Fundraiser fundraiser={fund ...

Discovering the method for retrieving JavaScript output in Selenium

Whenever I need to run JavaScript code, the following script has been proven to work effectively: from selenium import webdriver driver=webdriver.Firefox() driver.get("https:example.com") driver.execute_script('isLogin()') However, when I atte ...

What is the most effective way to set up HTTPS for handling all connections in Node.js?

In my project to create a stateless authentication system using Double Submit Cookie in Node.js/ExpressJs, I am exploring ways to ensure all connections are made over HTTPS. My goal is to optimize for handling high traffic while also prioritizing security ...

Steps for setting a background image behind radio buttons

I am currently facing a challenge in adding a background image to a div that contains some radio buttons and updating it dynamically with Angular based on the current page. app.controller('thingCtrl', function ($scope, $rootScope, $routeParams ...

What is the method for triggering a JavaScript function by clicking a button within a CakePHP application?

<button type="button" id="addleetdata" class="btn btn-primary addleetdata float-left">Add</button> JS File $("#addleetdata").click(function () { console.log("entering into function") startLoading(); console.log("editin ...

Protractor unable to locate elements using by.repeater

What is the best method for targeting this repeater with Protractor? <a ng-repeat="item in filteredItems = (items | filter:'abc')">{{item}}</a> ...