自己写的第一个angularjs的directive
app.directive('sss', function () {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope,elm) {
var day = (new Date().getDay() === 0 ? 7 : new Date().getDay());
if (scope.$index == day-1) {
angular.element(elm).addClass('red')
};
}
}
});
兜兜转转 发现没必要那么写的 只要传给页面$scope.today=new Date().getDay() === 0 ? 7 : new Date().getDay();
然后再ng-repeat当中写上一句 ng-class="{ture:'css style name'}[$index==today-1]"

浙公网安备 33010602011771号