CoffeeScript的 - 在引用前角pressions DOM节点是不允许的 [英] CoffeeScript - Referencing DOM nodes in Angular expressions is disallowed

查看:629
本文介绍了CoffeeScript的 - 在引用前角pressions DOM节点是不允许的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要问题是简单的:

My main question is simple :

控制器或指令内做的DOM操作时,但是我得到的错误,功能性完美的作品。

I get errors when doing DOM manipulation within Controllers or Directives however, the functionality works perfectly.

Error: [$parse:isecdom] Referencing DOM nodes in Angular expressions is disallowed! Expression: open()

我想忽略这些错误,并得到确认,这是安全的这样做,从的功能的角度(不是设计的角度来看)

I would like to ignore these errors, and get the confirmation that it is safe to do so, from a functionality perspective ( not a design perspective )

为了简单起见,我将AP preciate一个简单的回答这个问题没有质疑我需要这样做。

To keep things simple, I would appreciate a simple answer to this question without questioning my need to do this.

现在,若有人想更详细地讨论,我有这个要点是:
<一href=\"https://gist.github.com/kosz/04f916a5725d85045be5\">https://gist.github.com/kosz/04f916a5725d85045be5 (相关性:棱角分明,jQuery的,jQuery UI的对话)
与code我目前正在经历着这种行为。

Now, if anybody does want to discuss in more detail, I have this gist : https://gist.github.com/kosz/04f916a5725d85045be5 ( dependencies: angular, jquery, jquery ui dialog ) with the code i'm currently experiencing this behaviour in.

我已经做了我最好的,到目前为止,摆脱这种错误,并且根据我读,和文档,在角DOM操作似乎在指令得到鼓励。

I have done my best so far, to get rid of this error, and based on what i read, and the docs, dom manipulation in angular seems to be encouraged in the directives.

所以,我做了一个指令中的code的工作,但是,它仍然引发错误!?

So I've made the code work with a directive, however, it still throws the error !?

正如你可以看到我使用jQuery用户界面,并将其显示为每个列表项,如果用户希望编辑。我不是直接操作DOM,不过,我需要一种方法来控制jQuery UI的对话,不使角填补我的控制台有错误的关闭/打开事件。

As you can see I am using Jquery UI and showing it for each list item, if the user wants to edit. I am not directly manipulating the dom, however, i need a way to control the close/open events of the jQuery ui Dialog, which doesn't make Angular fill my console with errors.

在这个任何了解大大AP preciated。

Any insight on this is greatly appreciated.

请注意,我知道的角UI引导模式,而且它不是一个选项,我在这个特殊的情况下使用。

Please note that I am aware of the angular ui bootstrap modal, and it's not an option for me to use in this particular scenario.

推荐答案

由于错误状态,角不允许访问DOM节点前pressions。

As the error states, Angular disallows accessing DOM nodes in expressions.

CoffeeScript中使用一个隐含的收益如果没有指定。

CoffeeScript uses an implicit return if none is specified.

这意味着,在您的code例如 scope.open 功能:

This means that for example the scope.open function in your code will:

return element.dialog('open');

角会检测到这一点,并抛出错误。

Angular will detect this and throw the error.

如果您添加一个明确的收益它应该解决这个问题:

If you add an explicit return it should solve the issue:

scope.open = =>
  element.dialog('open') 
  return true

这篇关于CoffeeScript的 - 在引用前角pressions DOM节点是不允许的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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