Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using angularjs directive for icheck plugin

I've a problem with my Angularjs app, cannot figure out where is the problem.

check it on plunker Here

when I click the button it should run the iCheck() plugin, but it doesn't

like image 479
Ahmed Hashem Avatar asked Jun 25 '26 10:06

Ahmed Hashem


1 Answers

A better iCheck directive can be found here: https://github.com/fronteed/iCheck/issues/62 (wajatimur)

return {
    require: 'ngModel',
    link: function($scope, element, $attrs, ngModel) {
        return $timeout(function() {
            var value;
            value = $attrs['value'];

            $scope.$watch($attrs['ngModel'], function(newValue){
                $(element).iCheck('update');
            })

            return $(element).iCheck({
                checkboxClass: 'icheckbox_flat-aero',
                radioClass: 'iradio_flat-aero'

            }).on('ifChanged', function(event) {
                if ($(element).attr('type') === 'checkbox' && $attrs['ngModel']) {
                    $scope.$apply(function() {
                        return ngModel.$setViewValue(event.target.checked);
                    });
                }
                if ($(element).attr('type') === 'radio' && $attrs['ngModel']) {
                    return $scope.$apply(function() {
                        return ngModel.$setViewValue(value);
                    });
                }
            });
        });
    }
};
like image 107
perfect_element Avatar answered Jun 28 '26 01:06

perfect_element



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!