In my app, I have got different tasks, each having a due date thay may be like following:
Jun 6, 2014
Apr 12, 2014 @ 1pm
Daily @ 1pm
In my view, I am using ng-repeat
to show the tasks and their related information. My ng-repeat
looks like below:
<ul class="tasks">
<li class="single-task">
<span class="task-title">{{task.title}}</span>
<span class="task-duedate">{{task.dueDate}}</span>
</li>
What I want, is to show the dates differently i.e. instead of showing them the way that they are stored, I want the date to be rendered inside the <span class="task-duedate"></span>
like the following:
<span class="task-duedate">
<span class="date-daymon">Apr 12</span>
<span class="date-year">2014</span>
<span class="date-time">1 pm</span>
</span>
So, I have creatd and applied a filter
called NormalizeDateTime
<span class="task-duedate">{{task.dueDate | NormalizeDateTime }}</span>
that generates the desired html and returns it.
app.filter('NormalizeDate', function(){
return function( input ) {
...
...
return '<span..>' + date + '</span><span..>' + year + '</span><span..>' + time + '</span>';
};
});
Now the problem I am having is angular, instead of making the browser render the returned html, is showing the date part returned by the filter as it is i.e. in the form of plain text. Now the question is, how may I make it render the text returned by the NormalizeDateTime
filter as html?
P.S I have also tried triple braces {{{task.dueDate | NormalizeDateTime}}}
, as we do in HandlebarsJS
, but that doesn't work either.
UPDATE I have tried to achieve the same using a custom directive:
<span class="task-content group cursor-text group left">
<span class="task-text cursor-text">{{task.title}}</span>
<span class="task-trackedtime right">{{task.trackedTime}}</span>
<span class="task-datetime right" duedate="{{task.dueDate}}"></span>
</span>
Below is how my directive looks like:
app.directive('duedate', [function () {
return {
restrict: 'A',
// transclude: true,
replace: true,
template: '<span class="task-datetime right">{{dat}}</span>',
link: function (scope, iElement, iAttrs) {
// scope.dat = 'Testing Date';
console.log(iAttrs.duedate);
}
};
}])
But I'm unable to access iAttrs
.duedate
inside the link
of my directive. Why is it so?