当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How can I set ng-model in jQuery callback

问题描述:

<script>

$("#point-range").ionRangeSlider({

min: 0,

max: 10,

from: 1,

from_min: 1,

from_max: 10,

step: 1,

grid: true,

hide_min_max: true,

onFinish: function (data) {

$('#point-value').val(data.from);

}

});

</script>

How can I set value for ng-model when onFinish function is called. I try to set value into a hidden input:

onFinish: function (data) {

$('#point-value').val(data.from);

}

{{ Form::hidden('point', null, ['ng-model' => 'evaluationData.point', 'id' => 'point-value']) }}

But when I submit the form, I don't get evaluationData.point.

网友答案:

Try wrapping that script in a directive.

angular.module('myApp').directive('myDirective', function() {
    return {
        scope: 'ngModel',
        link: function(scope, element, attrs) {
            $("#point-range").ionRangeSlider({
                min: 0,
                max: 10,
                from: 1,
                from_min: 1,
                from_max: 10,
                step: 1,
                grid: true,
                hide_min_max: true,
                onFinish: function (data) {
                    $('#point-value').val(data.from);
                    scope.ngModel = 'Blah';
                    scope.$digest();
                }
            });
        }
    }
})
分享给朋友:
您可能感兴趣的文章:
随机阅读: