// get the filter function
var dayFilter = $filter("dayName");
// param detail:
// scope : view scope of action
// element : the element which uses the custom directive
// attrs : the attrs of the element
return function (scope,element,attrs) {
// console.log(dayFilter(scope.day));
if (dayFilter(scope.day) == attrs['highlight']) {
element.css("color",'red');
}
}
})
将指令应用于视图
...
第六步:定义过滤器
var dayNames = ['Sunday',"Monday",'Tuesday','Wednesday','Thurday','Friday','Saturday'];
return function (input) {
// input is the value of data binding
return angular.isNumber(input % 7) ? dayNames[input % 7] : input % 7;
};
})