什么是角料$事件,我需要它的用户界面路由器? [英] What is $event in Angular Material and do I need it with UI Router?

查看:161
本文介绍了什么是角料$事件,我需要它的用户界面路由器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也发现自己寻找到这个没有答案的问题但我也发现自己想知道如果找到答案的问题?我GOOGLE了 $事件,并通过双方的角度看材料(以及至少在API文档的左侧菜单中的项目)和材料的文档和没有找到任何引用。我只找到一个参考它在UI路由器文档,这表明它可以阻止事件的传播。

I too find myself looking into this unanswered question but I also find myself wondering if finding an answer matters? I've googled $event and looked through both angular material (well at least the items in the left hand menu of the API docs) and material docs and don't find any reference to it. I've only found a reference to it in the UI Router docs, suggesting it can stop event propagation.

那么什么是 $事件?为什么它传递到一个 $ mdDialog ?我需要它,如果我使用 UI路由器 的OnEnter

so what is $event? why is it passed into an $mdDialog? do I need it if I'm using ui-router onEnter?

推荐答案

直接从的文档:$事件对象是 jQuery的事件对象的实例当jQuery是present或类似jqLit​​e对象。

Directly from the docs: $event object is an instance of a jQuery Event Object when jQuery is present or a similar jqLite object.

在角材料的情况下,它被用于引用DOM事件对象,例如一个点击的事件对象中的 $ mdDialog

In the case of angular-material it is used to reference dom event object, for instance a click's event object is used in $mdDialog

更新:

您必须包装一个 NG-点击事件中的状态变化以获得 $事件对象,传递事件对象通过 $ state.go()

You will have to wrap your state change inside a ng-click event to get the $event object and pass that event object through $state.go():

<div ng-app="myApp" ng-controller="myController">
    <a ng-click="show($event)">add campaign</a>
</div>

然后配置你的状态:

And then configure your state:

.state("campaigns.add", {
    url: "/add",
    resolve: {
        event: function($stateParams) {
            return $stateParams.event;
        }
    },
    onEnter: function($mdDialog, $state) {
        var ev = null;

        $mdDialog.show(
        $mdDialog.alert()
            .parent(angular.element(document.body))
            .title('This is an alert title')
            .content('You can specify some description text in here.')
            .ariaLabel('Alert Dialog Demo')
            .ok('Got it!')
            .targetEvent(event)).then(function() {
                $state.go('done');
            });
        }
    })

下面是基于来自其他问题code工作演示:的http://的jsfiddle。净/ f30wesj3 / 2 /

Here is a working demo based on the code from the other question: http://jsfiddle.net/f30wesj3/2/

这篇关于什么是角料$事件,我需要它的用户界面路由器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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