angularjs:当我使用 jQuery 更改选择时 $scope 更新 [英] angularjs: $scope update when I change a select with jQuery

查看:24
本文介绍了angularjs:当我使用 jQuery 更改选择时 $scope 更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery 插件来自定义"我的选择.

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.

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

问题是我的范围没有改变.

The problem is that my scope doesn't change.

在这里您可以看到一个快速示例...更改选择范围会发生变化.单击选择更改但不更改范围的按钮.

Here you can see a quick example... changing the select the scope changes. clicking the buttons the select changes but not the scope.

http://plnkr.co/edit/pYzqeL6jrQdTNkqwF1HG?p=preview

我错过了什么?

推荐答案

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

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;
    });
});

这篇关于angularjs:当我使用 jQuery 更改选择时 $scope 更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆