且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

angularjs:当我使用 jQuery 更改选择时 $scope 更新

更新时间:2023-12-02 10:34:58

需要访问下拉的范围,然后应用如下图:

You need to access the scope of the dropdown and then apply it as shown below:

$('button').on('click', function(){
    var newVal = $(this).data('val');
    $('select').val(newVal).change();

    var scope = angular.element($("select")).scope();
    scope.$apply(function(){
        scope.selectValue = newVal;
    });
});