Update the value in JSON upon the click of a button

Currently, I am dealing with a nested buttonclick situation inside another buttonclick. Right now, my alert is working fine.

        $scope.getid = function (order) {

            $scope.chosen.id = order.id;
            $scope.chosen.status = order.point;

            $scope.start = function (time) {
                alert(order.point)
            }
        };

I am looking to update the value of order.point and assign it a new value.

            $scope.start = function (time) {
              // Insert new value logic here
                order.point = ('2')
            }

Your help will be highly appreciated. Thank you in advance.

Answer №1

As mentioned by another user, the question wasn't clear initially. It's not possible to add a function inside another function. However, if you want to change the json value in angularjs on click action, you can achieve it using the following approach:

JSFiddle

var app = angular.module('myApp', []);
app.controller('Controller', function ($scope) {
    $scope.start = function (records) {
        alert(records.col1);
        records.col1 = 'test1';
        alert(JSON.stringify($scope.records));
        
    }
    $scope.records = {
        col1: 'a1',
        col2: 'd1'
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp' ng-controller="Controller">
    <button ng-click="start(records)">Change</button>
</div>

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

What is the best way to trigger a function exclusively upon clicking a particular element?

My goal is to enable the user to interact with the model by positioning cubes in space upon clicking the "Cubes Mode" button. I currently have a script from the three.js website that achieves this, but I want it to only run when the mentioned button is cli ...

How can I simulate the response of a VueX action using Vue-test-utils?

I am currently developing a test for a Vue component that interacts with a module store to execute an action and utilize the result from it. Since the action involves making requests to our API, I prefer not to run the test using the actual action. Instea ...

Issue with base64 in Discord.js captcha channel system

Greetings everyone, and a special welcome to those willing to assist me. I am currently working on a project that involves verifying users through a hash decryption challenge system (base64). However, I've encountered an issue where the verification p ...

Changes in UI-Router states are occurring, however, the URL and template remain static

When implementing onStateChange authorization, I have the following code: angular .module('app') .run(['$rootScope', '$state', 'Auth', function ($rootScope, $state, Auth) { $rootScope.$on("$stateCha ...

Retrieving items from an array using the Jackson Streaming API

Recently, I've delved into utilizing the Jackson Streaming API in Java to handle the following JSON structure: { "objs": [ { "A": { "a": "b", "c": "d" }, "B": { "e": "f", "g": "h" }, } ...

Improvement in Select2 Change Event: Update the subsequent select2 box options based on the value change in the preceding select2 box

I need assistance with two select boxes, namely Category and Sub-category. My objective is to dynamically alter the available options in the subcategory box based upon the value selected in the category box. Additionally, I would like to load data for the ...

When clicking on links that are not within the ng-view element, you will be redirected to the

I'm having trouble coming up with a name for this question, but here's my current situation This is the structure of my template: ├── index.html ├── ... ├── account │ ├── index.html │ ├── authorizat ...

Troubles with Angular elements not aligning correctly when using the "display: block" property

When using an angular element for a directive with "display: block", it may not automatically take up 100% of the width of the parent container. In order to ensure that it does, the width must be explicitly set to "100%" in the CSS. Despite setting "width: ...

Get the Label Values Based on CheckBox Status

Is there a way to retrieve the values of labels corresponding to checkboxes in HTML? I have multiple labels and checkboxes next to each other, and I want to be able to get the label values if the checkbox is checked. Can you provide guidance on how to do ...

The JSONP file can be successfully retrieved through an AJAX request in the console, however, the data does not display when attempting

Currently attempting to send an ajax request utilizing the following code snippet: $.ajax({ url: "http://mywebsite.com/blog/json", dataType: "jsonp", jsonpCallback: "jsonpCallback" }); function jsonpCallback(data) { console.log(data); } E ...

A guide on incorporating dynamic formControlName functionality into AngularJs2

Currently, I am building forms using the form builder in AngularJS2. My goal is to incorporate the formControlName property/attribute into the form element as shown below: <input type="text" formControlName={{'client_name' + i}} placeholder=" ...

What is the reason behind this error: Error: connect ECONNREFUSED?

I am facing an issue while trying to establish a connection with the Mailchimp API. The error occurs when I run the app.js file. import mailchimp from "@mailchimp/mailchimp_marketing"; mailchimp.setConfig({ apiKey: "apiKey", server ...

Creating a classification for a higher order function

In the code snippet below, I have a controller that acts as a higher order method: const CourseController = { createCourse: ({ CourseService }) => async (httpRequest) => { const course = await CourseService.doCreateCourse(httpRequest. ...

Unable to use virtual path to add script tag

**Success with this code:** <script src="Scripts/angular.js"></script> **However, the following code does not work:** <script src="~/Scripts/angular.js"></script> Would anyone be able to clarify why the second option is not functio ...

The `await` keyword can only be used within an `async` function in

I attempted to create a music bot for my server, but it seems like I made a mistake. I followed instructions from this video, however, an error stating await is only valid in async function keeps popping up. module.exports = (msg) => { const ytdl ...

Locate the div element containing specific text and remove the text from the

Is there a way to locate a div that contains specific text and remove only that specific text from the div? For instance: <div> DeleteText <span>Something text</span> <div>Something span inner text </div> </div> I am l ...

Having trouble with Postgres not establishing a connection with Heroku

My website is hosted on Heroku, but I keep encountering the same error message: 2018-05-06T19:28:52.212104+00:00 app[web.1]:AssertionError [ERR_ASSERTION]: false == true 2018-05-06T19:28:52.212106+00:00 app[web.1]:at Object.exports.connect (_tls_wrap.js:1 ...

Display in Google Chrome without any dialogues

Hello friends, I am currently working on adding a print button to my website. I am testing it in Chrome and would like the page to be printed directly without showing any dialog boxes. However, I am facing some difficulties with this process. If anyone has ...

Output the following by using the given format: *a* -> *a1**aabbbaa* -> *a2b3a2*

I am a beginner in JavaScript. Could you please explain how to achieve the following output? * "a" -> "a1" * "aabbbaa" -> "a2b3a2" I attempted using a hash map, but my test cases are failing. Below is the code I have writt ...

Having trouble getting Jquery Ajax Post to work properly when using JinJa Templating?

Objective: My goal is simple - to click a button and post information to a database. Problem: Unfortunately, clicking the button doesn't seem to be posting to the database as expected. Setup: I am working with Flask Framework, Jquery, and Jinja Temp ...