0

I have this object:

data= {
       date_code: '',
       status_code: '',
       date_order: '2017-08-04T18:30:00.000Z',
       date_due: '2017-08-04T18:30:00.000Z',
       date_dispatch: '2017-08-04T18:30:00.000Z',
};

And this function to perform submit data as json :

vm.onSubmit = function (data) {
            const dateOrder = data["date_order"];
            dateOrder = dateOrder.slice(0, 10);
            data["date_order"] = dateOrder;
            var json = JSON.stringify(data);
            $scope.table.jsonData = json;
};

I want to get the value of "date_order" and store it to var for slice the date.

How can I do that in angularjs?

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108

2 Answers2

2

Very simple - just use regular JS to grab it, angular is not a concern here.

const data = {
       date_code: '',
       status_code: '',
       date_order: '2017-08-04T18:30:00.000Z',
       date_due: '2017-08-04T18:30:00.000Z',
       date_dispatch: '2017-08-04T18:30:00.000Z',
};

const dateOrder = data["date_order"]

console.log(dateOrder)
Christopher Messer
  • 2,040
  • 9
  • 13
  • 1
    Or you can use the dot notation provided there are no spaces and special characters except underscore. `var dateOrder = data.date_order` – Abana Clara Aug 25 '17 at 05:36
  • I have to get it in the angular controller.. –  Aug 25 '17 at 05:42
0

You can do this:

data= {
       date_code: '',
       status_code: '',
       date_order: '2017-08-04T18:30:00.000Z',
       date_due: '2017-08-04T18:30:00.000Z',
       date_dispatch: '2017-08-04T18:30:00.000Z',
};

console.log(data.date_order);
var dateOrder = data.date_order;
var datePart = dateOrder.split("T")[0];
console.log(datePart);

After that you can assign it to the $scope like this:

$scope.table.jsonData = datePart;

Part which worked:

var dateOrder = data["date_order"];
date = dateOrder.split("T")[0];
data["date_order"] = date;
var json = JSON.stringify(data);
$scope.table.jsonData = json;
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108