MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / checkboxInputType

Function checkboxInputType

code/songhop/www/lib/angular/angular.js:19918–19946  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse)

Source from the content-addressed store, hash-verified

19916}
19917
19918function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse) {
19919 var trueValue = parseConstantExpr($parse, scope, 'ngTrueValue', attr.ngTrueValue, true);
19920 var falseValue = parseConstantExpr($parse, scope, 'ngFalseValue', attr.ngFalseValue, false);
19921
19922 var listener = function(ev) {
19923 ctrl.$setViewValue(element[0].checked, ev && ev.type);
19924 };
19925
19926 element.on('click', listener);
19927
19928 ctrl.$render = function() {
19929 element[0].checked = ctrl.$viewValue;
19930 };
19931
19932 // Override the standard `$isEmpty` because the $viewValue of an empty checkbox is always set to `false`
19933 // This is because of the parser below, which compares the `$modelValue` with `trueValue` to convert
19934 // it to a boolean.
19935 ctrl.$isEmpty = function(value) {
19936 return value === false;
19937 };
19938
19939 ctrl.$formatters.push(function(value) {
19940 return equals(value, trueValue);
19941 });
19942
19943 ctrl.$parsers.push(function(value) {
19944 return value ? trueValue : falseValue;
19945 });
19946}
19947
19948
19949/**

Callers

nothing calls this directly

Calls 2

parseConstantExprFunction · 0.70
equalsFunction · 0.70

Tested by

no test coverage detected