agon024 agon024 - 1 year ago 76
Javascript Question

AngularJS - Adding a variable value back into controller $scope

I have a date that is being being returned in the format:

2016-07-25 10:50:14

I've created a variable that gets the data and strips out the dashes, spaces and colons with:

var newDate = $scope.details["Created At"].replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '');

Now the with console.log(date); the date is being returned as:


I guess my main question is how can I take that variable data and add it back into the controller $scope so that I can call it into my html and use angular date formatting such as:

{{ details.newDate | date:'MM/dd/yyyy @ h:mma' }}

Thanks for any help.

Answer Source

Should be something like

$scope.details.newDate = $scope.details["Created At"].replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download