Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  33] [ 7]  / answers: 1 / hits: 34476  / 12 Years ago, mon, september 17, 2012, 12:00:00

Currently in the process of converting a website from its previous templating to Angular. In the previous templating process we were using we were able to call helper methods to display data correctly. For instance:



<script type=text/javascript>
$.views.helpers({
parseDate: function (jsonDate) {
if (jsonDate != null) {
var newDate = Utils.PrettyDate(Utils.ConvertJsonDateToJsDate(jsonDate));
return newDate;
}
}
});
</script>


<div class=post-info>
<span class=posted-date>Posted {{ :~parseDate(CreatedDate) }}</span>
&nbsp|&nbsp
<span>{{ :ReplyCount }} Replies</span>
</div>


This was very nice. Trying to figure out a way to utilize the same type of functionality with Angular as far as templating goes. Is it possible to do something similar? If so how?


More From » templates

 Answers
46

You simply add the method to your controller. Something like this:



<div class=post-info ng-controller=MyCtrl>
<span class=posted-date>Posted {{parseDate(CreatedDate)}}</span>
</div>


Then the controller:



function MyCtrl($scope)
{
$scope.parseDate = function(jsonDate) {
//date parsing functionality
return newParsedDate;
}
}

[#83044] Saturday, September 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antonb

Total Points: 424
Total Questions: 104
Total Answers: 101

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;