0

I am trying to create a checkbox directive with angularjs.The code is here in JSFIDDLE

It works fine only with ng-model and text.

But if i add ng-true-value and ng-false value, it throw error as

nged2angular.js:12520 Error: [ngModel:constexpr] Expected constant expression for `ngTrueValue`, but saw `bindedTrueValue`.

Also i need to take the ng-change controller function inside the directive.

1 Answer 1

0

Well two things,

Firstly, you are passing 'checkboxChanged' function to the directive, so u need to use &ngChange in the directive scope instead of =ngChange.

Without {{}}, bindedTrueValue and bindedFalseValue will be considered as strings rather than an angular variable from controller. So, It should be changed to

<input type="checkbox" ng-model="bindedModel" ng-true-value="{{bindedTrueValue}}" ng-false-value="{{bindedFalseValue}}" ng-change="bindedChange">

Check this codepen for working demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.