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

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

问题描述

我使用一个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.

的问题是,我的范围不改变

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.

<一个href=\"http://plnkr.co/edit/pYzqeL6jrQdTNkqwF1HG?p=$p$pview\">http://plnkr.co/edit/pYzqeL6jrQdTNkqwF1HG?p=$p$pview

我是什么失踪?

推荐答案

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

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一个选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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