1

I'm trying to create custom input directive which will override default behavior of checkbox input. I can't seem to find a solution that would prevent default checkbox input directive from executing.

I've tried to just decorate the input, with priority of custom directive set to 0.

<input type="checkbox" my-custom-directive="0" ng-model="MyList" /> 

I've also tried to use a template and replace different element type.

<div my-custom-directive="0" ng-model="MyList"></div> // part of directive object return { restrict: 'A', template: '<input type="checkbox" />', replace: true, terminal: true, priority: 0, ... } 

Ultimately what I'm trying to do is to bind a check box input to an array, and create behavior such that if a certain value is member of the array, input will be checked, otherwise it will not be checked. Also, if user checks the input box, directive will add mentioned value into the array.

    1 Answer 1

    1

    In the end I've solved it by using ngNonBindable directive. I really dislike this solution because in more complex scenarios I might still want to use binding on certain elements of the template. If someone else has a better idea, I'll accept that answer once it appears.

    return { restrict: 'A', template: '<input type="checkbox" ng-non-bindable />', replace: true, terminal: true, priority: 0, ... } 

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.