自己写的第一个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]"

posted @ 2013-12-20 14:37  霏霏雪无声  阅读(139)  评论(0)    收藏  举报