The process by which an angular shape acquires the properties of a different object

How do I ensure that the object inherits all properties from another object?

Here is the code snippet:

this.makeReady = function(order) {
    var tempOrder = angular.copy(order);
    tempOrder.status = 1;
    angular.forEach(tempOrder.items, function(item){
        item.status = 1;
    })
    return $http.put('/rest/change/invoice/'+order.id+'/', tempOrder).success(function(){
        order = tempOrder; // this method does not work as expected
    });
}

If successful, update the object value accordingly.

Answer №1

Try updating the order directly in the $scope.allOrders array to see if it achieves the desired outcome.

    Modify the function like this:
    this.makeReady = function (order) {
        var tempOrder = angular.copy(order);
        var orderIndex = $scope.allOrders.indexOf(order);
        tempOrder.status = 1;

        angular.forEach(tempOrder.items, function(item) {
            item.status = 1;
        });

        return $http.put('/rest/change/invoice/' + order.id + '/', tempOrder).success(function () {
            $scope.allOrders[orderIndex] = tempOrder;
        });
    }

Answer №2

implement this

this.prepare = function(regulation) {
    var tempRegulation = angular.copy(regulation);
    tempRegulation.state = 1;
    angular.forEach(tempRegulation.details, function(detail){
        detail.state = 1;
    })
    $http.put('/api/adjust/rule/'+regulation.id+'/', tempRegulation).success(function(){
        regulation = tempRegulation; // this doesn't do the job
        return regulation;
    });
}

alternatively, utilize a callback function

  this.prepare = function(regulation, callback) {
        var tempRegulation = angular.copy(regulation);
        tempRegulation.state = 1;
        angular.forEach(tempRegulation.details, function(detail){
            detail.state = 1;
        })
        $http.put('/api/adjust/rule/'+regulation.id+'/', tempRegulation).success(function(){
            regulation = tempRegulation; // this isn't effective
            callback(regulation)
        });
    };

invoke the function

this.prepare({state:1, value:2, details:{state:1}}, function(data){
// here is the information regarding your order in the service
})

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

Creating non-modal or modeless dialog boxes in AngularJS can be achieved without relying on external libraries like jquery-ui

In my AngularJS application, I am endeavoring to create non-modal dialogs without the use of Bootstrap modal. Instead, I am seeking to develop a draggable dialog that remains active while allowing interaction with the background (non-modal). Although I h ...

Loading indicator for the Worklight application

Our app's loading process is quite lengthy, so to keep the user informed that the app is indeed working and just needs time to load, we decided to implement a loading/initializing indicator. I initially attempted to use WL's busy indicator but fo ...

Implementing AJAX to dynamically update information based on user's selection from a dropdown

I need to dynamically adjust the opacity of my graph bars without requiring the user to manually refresh the page. I'm considering using AJAX for this purpose. How can I implement this functionality? const opacitySlider = document.getEle ...

Alter the input field value in Selenium with Python

I'm having trouble updating the input field value in a form, even after attempting various methods. The input value can be found at this URL Email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="df89bab3bef1bebbb2b69fb8b ...

Converting an array into an object while retaining the original input names using JavaScript

After spending all night trying various solutions, I still can't find the right answer for my Javascript needs as a beginner. The solution I attempted to convert my form data into an object is: $('input.submit').click(function(e){ e.preve ...

What is the best way to organize a php associative array in a custom sequence?

This is the array that I would like to organize in a specific order $data = Array ( [break] => Array ( [Indoor room] => 42 [Gym Class] => 19 ) [finish] => Array ( [Indoor ro ...

Updating data-bind ng-model textarea in AngularJS scope is not reflecting changes

I encountered an issue while trying to reset a textarea using a function that I created. The problem is that although the scope updates as expected, the textarea bound by ng-model does not update. Below is a simplified version of the code: In Controller ...

Develop a back button for PHP data fetched from a database

I have recently developed a quiz exam website where users can answer questions retrieved from a database. The structure of the website includes HTML and AJAX to call PHP functions for handling the questions. Each question is displayed one at a time to the ...

issue with uploading files in firefox

Within my asp.net page, I have the following code: <input id="MyTextBox" runat="server" type="text" name="T1" size="20"/> <asp:Button ID="UploadFileButton" runat="server" Text="Upload" /> <input id="FileUpload" runat="server" type="file ...

AngularJS encountered an error following a successful GET request

I'm attempting to retrieve data from the server using this code snippet. $scope.get_file_list = function() { delete $http.defaults.headers.common['X-Requested-With']; //We don't want OPTIONS but GET request $htt ...

The Enigmatic Nature of IFS Behavior

After exploring this post on Stack Overflow, I discovered that I can divide a string into an array using the IFS method. Similarly, in this other post on Stack Overflow, I learned about joining an array using an IFS delimiter. However, during my test bel ...

AngularJS Security Measures: Ensuring Protection for Your Applications

Greetings! I am interested in learning more about the security features of AngularJS. From what I have gathered, Angular offers built-in protection against common security vulnerabilities. Angular prevents cross-site scripting attacks. It also protects a ...

Executing multiple concurrent progress lines in the Node.js console using Node.js Puppeteer

I developed a basic script that automates file uploads on a website. Utilizing puppeteer for headless browsing, I handle login and file uploading processes. To track changes in the upload progress bar, I have implemented a mutation observer injected into t ...

What is the best way to access data from outside a forEach loop in JavaScript?

I am trying to access the value of my uid outside of the foreach loop in my code. Can anyone assist me with this? This is the code I am working with: var conf_url = "https://192.168.236.33/confbridge_participants/conference_participants.json?cid=009000 ...

Can one use Javascript to access the Sharepoint REST API from an external source?

I'm looking to showcase the content of a Sharepoint list on an external webpage. I'm interested in using Javascript or PHP to make a REST call to Sharepoint for this purpose. Although I've researched Sharepoint's REST API, I'm uns ...

Steps to bring life to your JavaScript counter animation

I need to slow down the counting of values in JavaScript from 0 to 100, so that it takes 3 seconds instead of happening instantly. Can anyone help me with this? <span><span id="counter"> </span> of 100 files</span> <s ...

Unable to initiate TypeScript program in Visual Studio Code: "The program 'hw.ts' cannot be launched as the corresponding JavaScript file is missing."

In my file named hw.ts, the code is as follows: function greeter(x: string) { return "Hello" + x; } let u = "John"; document.body.innerHTML = greeter(u); When I try to run it using Start without debugging in VSCode, I get an error message: Cannot l ...

AngularJS dynamic drop-downs with filtered values appearing successively

Is it possible to create cascading drop-down menus where the second drop-down only shows options that partially match the selection from the first drop-down? EXAMPLE: DROPDOWN1: TOOL1 DROPDOWN2: TAGFORTOOL1 TOOL2 TAGFORTO ...

Provide a numerical representation of how frequently one object value is found within another object value

Account Object Example in the Accounts Array: const accounts = [ { id: "5f446f2ecfaf0310387c9603", picture: "https://api.adorable.io/avatars/75/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6b7d7a666 ...

Handling Ajax Posts in AngularJS and Symfony2: Dealing with Undefined Index Issue

My journey with the Symfony2 PHP framework is just beginning, and I am aware that it follows the MVC pattern for backend development. One of my current tasks involves creating a form that stores data in a database and then sends an email to the user with t ...