agon024
agon024

Reputation: 1007

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:

20160725105014

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.

Upvotes: 0

Views: 51

Answers (2)

Munam Yousuf
Munam Yousuf

Reputation: 547

Once you have your desired value in a variable "newDate" you can then assign that same variable to some other $scope variable to be used in your view.

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

Upvotes: 1

d3l33t
d3l33t

Reputation: 890

Should be something like

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

Upvotes: 1

Related Questions