angularjs: $scope update when I change a select with jQuery

前端 未结 5 2009
感动是毒
感动是毒 2020-12-09 05:30

I\'m using a jQuery plugin to \'customize\' my selects.

This plugin fires the change event of the original select when some option is selected.

The problem i

5条回答
  •  无人及你
    2020-12-09 05:51

    When you click the button, angular goes out of its scope and uses jquery to manipulate the data/to perform some action, so we need to exlicitly call $scope.$apply() to reflect the changes back into the scope of the controller. And change your controller to this:

    app.controller('AppCtrl', function($scope) {
        $('button').on('click', function(){
            $scope.selectValue=$(this).data('val');
            $scope.$apply();
        });
    }
    

    By the way you can use jquery event inside the angular..

提交回复
热议问题