Passing dynamic value with single quote as a ng-true-value expression fails

前端 未结 2 1216
無奈伤痛
無奈伤痛 2021-01-06 00:51

I have my checkbox input that sets the \"true\" value dynamically based on a variable trueVal, which is a string.



        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-06 01:29

    Try this.

    In Markup

    
    

    In Controller

    var trueValue = "my true' value";
    var falseValue = false;
    var _model;
    $scope.dummyModel = function (val) {
        if (angular.isDefined(val)) {
            _model = val ? trueValue : falseValue
        }
        return _model === trueValue;
    }
    

    Use _model to submit to the database.

提交回复
热议问题