如何访问我从jQuery的对话框按钮的角度范围是什么? [英] How do I access my angular scope from jQuery dialog buttons?

查看:125
本文介绍了如何访问我从jQuery的对话框按钮的角度范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://plnkr.co/edit/Rf0VItthVBg6j0z7KudO

我使用jQuery的对话,并希望使用该对话框按钮,但我不知道如何在范围得到触发(目前不存在)$ http或$资源回调与服务器点击jQuery的对话框按钮时,更新后的模型。我觉得如果我要对此错误的,但我不知道这里什么方向走。

I'm using a jQuery dialog and want to use the dialog buttons, but I don't know how to get at the scope to trigger a (currently non-existent) $http or $resource call back to the server with the updated model when the jQuery dialog button is clicked. I feel as if I'm going about this wrong, but I don't know what direction to go here.

推荐答案

您可以使用角功能找到连接到一个元素的范围,并调用它的功能。我preFER真正抽象它拿走,并找到根NG-应用和广播事件到应用程序,以便在由外向内code没有按'知道关于内部code,除了为您广播该事件的具体细节。

You can use Angular functions to find the scope attached to an element and call a function on it. I prefer to really abstract it away and find the root of the ng-app and broadcast an event into the app so that the outside-code doesn't know about the specifics of the inside code except for the event that you broadcast.

angular.$externalBroadcast = function (selector, event, message) {
    var scope = angular.element(selector).scope();

    scope.$apply(function () {
        scope.$broadcast(event, message);
    });
};

然后,从任何code,你可以调用是这样的:

Then, from any code, you can call something like:

angular.$externalBroadcast('#app-container', 'doSomething', parameters);

和在应用程序中,我会做这样的事情:

And inside the app, I'd do something like this:

$rootScope.$on('doSomething', function(parameters) {
    // handle the external event.
});

如果你不喜欢这种方式,只是得到的范围:

If you don't like this approach, just get the scope:

var scope = angular.element(selector).scope();

和用它做什么。只要确保你叫范围。$适用否则消化周期将不会发生。

And do something with it. Just make sure you call scope.$apply or else the digestion cycle won't happen.

这篇关于如何访问我从jQuery的对话框按钮的角度范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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