adam
adam

Reputation: 41

Change value in json on buttonclick

I have a buttonclick inside a buttonclick. My alert works atm.

        $scope.getid = function (order) {

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

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



        };

I want to change order.point and give it a new value

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

Thank you in advance

Upvotes: 0

Views: 971

Answers (1)

Nidhish Krishnan
Nidhish Krishnan

Reputation: 20751

As @karlingen mentioned I also didn't understand your question properly, You cant add a function inside another function. But in fact if you want to change the json value in angularjs on click action you can do like this

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>

Upvotes: 1

Related Questions