0

I have date in format ISO8601 and I have to reformat it to format 'dd/MM/yy HH:mm:ss' in directive but it's not working. The date is displayd in original format.

directive:

app.directive('createTimeDirective', function ($filter) {
    return {
        restrict: 'E',
        template: '<div style="font-size: 9px;"> Created at {{date2}}<div>',
        //replace: true,
        scope: {
            date: '@'
        },
        link: function (scope, elem, attrs) {
            var dateFormat = 'dd/MM/yy HH:mm:ss';
            //scope.date = attrs.date;
            scope.date2 = $filter('date')(attrs.date, dateFormat);
            console.log(scope);

        }
    };
});

directive usage:

<create-time-directive date="'{{notices[$index].CreationTime}}'"></create-time-directive>|
1
  • 2
    It should be {{notices[$index].CreationTime}}, not '{{notices[$index].CreationTime}}'. Remove the single quotes. Commented May 23, 2016 at 6:14

1 Answer 1

1

Yes, answer from JB Nizet was good:).

But the full solution is here:

directive usage (removed single quotes):

<create-time-directive date="{{notices[$index].CreationTime}}"></create-time-directive>|

directive updated:

app.directive('createTimeDirective', ['$filter', function ($filter) {
    return {
        restrict: 'E',
        template: '<div style="font-size: 9px;"> Created at {{date2}}<div>',        
        scope: {
        date: '@'
    },
        link: function (scope, elem, attrs) {
            var dateFormat = 'dd/MM/yy HH:mm:ss';        
            scope.date2 = $filter('date')(attrs.date, dateFormat);            
        }
};
}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.