@@ -807,8 +807,8 @@ var inputType = {
807
807
*
808
808
* @param {string } ngModel Assignable angular expression to data-bind to.
809
809
* @param {string= } name Property name of the form under which the control is published.
810
- * @param {string = } ngTrueValue The value to which the expression should be set when selected.
811
- * @param {string = } ngFalseValue The value to which the expression should be set when not selected.
810
+ * @param {expression = } ngTrueValue The value to which the expression should be set when selected.
811
+ * @param {expression = } ngFalseValue The value to which the expression should be set when not selected.
812
812
* @param {string= } ngChange Angular expression to be executed when input changes due to user
813
813
* interaction with the input element.
814
814
*
@@ -824,7 +824,7 @@ var inputType = {
824
824
<form name="myForm" ng-controller="Ctrl">
825
825
Value1: <input type="checkbox" ng-model="value1"> <br/>
826
826
Value2: <input type="checkbox" ng-model="value2"
827
- ng-true-value="YES" ng-false-value="NO "> <br/>
827
+ ng-true-value="' YES' " ng-false-value="'NO' "> <br/>
828
828
<tt>value1 = {{value1}}</tt><br/>
829
829
<tt>value2 = {{value2}}</tt><br/>
830
830
</form>
@@ -1183,12 +1183,22 @@ function radioInputType(scope, element, attr, ctrl) {
1183
1183
attr . $observe ( 'value' , ctrl . $render ) ;
1184
1184
}
1185
1185
1186
- function checkboxInputType ( scope , element , attr , ctrl ) {
1187
- var trueValue = attr . ngTrueValue ,
1188
- falseValue = attr . ngFalseValue ;
1186
+ function parseConstantExpr ( $parse , context , name , expression , fallback ) {
1187
+ var parseFn ;
1188
+ if ( isDefined ( expression ) ) {
1189
+ parseFn = $parse ( expression ) ;
1190
+ if ( ! parseFn . constant ) {
1191
+ throw new minErr ( 'ngModel' ) ( 'constexpr' , 'Expected constant expression for `{0}`, but saw ' +
1192
+ '`{1}`.' , name , expression ) ;
1193
+ }
1194
+ return parseFn ( context ) ;
1195
+ }
1196
+ return fallback ;
1197
+ }
1189
1198
1190
- if ( ! isString ( trueValue ) ) trueValue = true ;
1191
- if ( ! isString ( falseValue ) ) falseValue = false ;
1199
+ function checkboxInputType ( scope , element , attr , ctrl , $sniffer , $browser , $filter , $parse ) {
1200
+ var trueValue = parseConstantExpr ( $parse , scope , 'ngTrueValue' , attr . ngTrueValue , true ) ;
1201
+ var falseValue = parseConstantExpr ( $parse , scope , 'ngFalseValue' , attr . ngFalseValue , false ) ;
1192
1202
1193
1203
var listener = function ( ev ) {
1194
1204
scope . $apply ( function ( ) {
@@ -1208,7 +1218,7 @@ function checkboxInputType(scope, element, attr, ctrl) {
1208
1218
} ;
1209
1219
1210
1220
ctrl . $formatters . push ( function ( value ) {
1211
- return value === trueValue ;
1221
+ return equals ( value , trueValue ) ;
1212
1222
} ) ;
1213
1223
1214
1224
ctrl . $parsers . push ( function ( value ) {
@@ -1356,14 +1366,15 @@ function checkboxInputType(scope, element, attr, ctrl) {
1356
1366
</file>
1357
1367
</example>
1358
1368
*/
1359
- var inputDirective = [ '$browser' , '$sniffer' , '$filter' , function ( $browser , $sniffer , $filter ) {
1369
+ var inputDirective = [ '$browser' , '$sniffer' , '$filter' , '$parse' ,
1370
+ function ( $browser , $sniffer , $filter , $parse ) {
1360
1371
return {
1361
1372
restrict : 'E' ,
1362
1373
require : [ '?ngModel' ] ,
1363
1374
link : function ( scope , element , attr , ctrls ) {
1364
1375
if ( ctrls [ 0 ] ) {
1365
1376
( inputType [ lowercase ( attr . type ) ] || inputType . text ) ( scope , element , attr , ctrls [ 0 ] , $sniffer ,
1366
- $browser , $filter ) ;
1377
+ $browser , $filter , $parse ) ;
1367
1378
}
1368
1379
}
1369
1380
} ;
0 commit comments