javascript - Invoke function from div with angularJS parameter -
below i'm attempting convert millisecond javascript date :
<div ng-app> <div ng-controller="todoctrl"> <div> <script type="text/javascript"> parsedate({{test}}) </script> </div> </div> </div> function todoctrl($scope) { $scope.test = "1429831430363" } function parsedate(date) { var months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; return months[date.getutcmonth()] + ' ' + date.getutcdate(); }
http://jsfiddle.net/u3pvm/15141/
but error uncaught syntaxerror: unexpected token {
thrown on console.
what correct method of invoking function div angularjs parameter ?
use code : see fiddle
<div ng-app> <div ng-controller="todoctrl"> <div> {{parsedate(test)}} </div> </div> </div> function todoctrl($scope) { $scope.test = "1429831430363" $scope.parsedate=function(date) { var months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; return months[(new date()).getutcmonth()] + ' ' + (new date()).getutcdate(); } }
Comments
Post a Comment