0

I have a span in ng-repeat as follows:

span(humanize-date="{{file.date}}"

I'm to create a directive so that, directive changes the date format

directive('humanizeDate', [
  function() {
    return {
      restrict: 'EA',
      template: '<div value="{{formattedDate}}"/>',
      replace: true,
      scope: {
        formattedDate: '=humanizeDate'
      },
      link: function(scope, elem, attrs) {
        return scope.formatedDate = moment.duration(scope.humanizeDate).humanize();
      }
    };
  }
]);

2 Answers 2

1

just use:

<span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>

here is more information about https://docs.angularjs.org/api/ng/filter/date

hope to help

Sign up to request clarification or add additional context in comments.

Comments

0

You should not use {{}} while you are using = inside your directive which indicated two way binding.

It should be direct variable reference rather than {{}}

span(humanize-date="file.date"

OR

Other way would be you could use @ in your directive isolated scope as your are giving {{}} with expression to attribute which indicated one way binding.

scope: {
  formattedDate: '@humanizeDate'
},

1 Comment

@user3840211 does it helped you?

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.