角 - 可重复使用的对话 [英] angular - reusable dialogs

查看:103
本文介绍了角 - 可重复使用的对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建立一个对​​话框来与任何项目的项目列表上使用。该对话框是pretty大致相同,除了这是明显的依赖项字段的值的项目无关。

I need to build a dialog to be used with any item on a list of items. The dialog is pretty much the same regardless of the item except for the values of the fields which are obviously item dependent.

该指令我建立是从文件中读取的模板,编译它与$编译,然后绑定(链接)到项目的范围。结合的结果是一个DOM树。为了使对话框中可见我需要这棵树添加一些元素在现有的DOM。我对话的性质是这样的,它是有道理的直接追加到它身上的标签。该对话框将被列入名单应用于不同的项目组合多次

The directive I am building is reading the template from a file, compiles it with $compile and then binds (links) it to the scope of the item. The result of the binding is a DOM tree. To make the dialog visible I need to append this tree to some element in the existing DOM. The nature of my dialog is such that it makes sense to append it directly to the body tag. The dialog will be used many times in combination with different items on the list

因此​​,这里是我的问题:如何这个过程中有多少(编译,绑定附加)可以提前做了什么?我当然也可以运行编译一次。我还可以在编译的结果绑定到$ rootscope和append(隐藏)它身体标记。这样我可以在以后只需打开知名度,并显示该对话框。

So here is my question: How much of this process (compile, bind, append) can be done in advance? I certainly can run compile once. I can also bind the compilation result to the $rootscope and append (hidden) it to the body tag. This way I can later just turn on visibility and show the dialog.

但是,如果它已经绑定并连接到DOM,它是犹太吧,如果这样再结合一些其他的范围 - 什么是应该做的正确方法?另一个问题是它甚至值得吗?可能只是每次需要时重新插入呢?

But if it is already bound and attached to DOM, is it kosher to re-bind it to some other scope, if so - what's the right way to do it? Another question is is it even worth it? might be just re-insert it every time it is needed?

推荐答案

非常好的问题,我认为。如果能热插拔元素的范围,你想知道的。我不知道是否有一种方法可以做到这一点,或者即使有,如果是这样的角方式。我想你看如何 NG-视图工作得到尽可能你已经得到?

Excellent question I think. You're wondering if one can "hot swap" the scope of an element. I don't know if there's a way to do that, or even if there is, if that's the Angular way. I take it you looked at how ng-view works to get as far as you've gotten?

我的建议是做$编译一次,保持结果的链接,或transclusion功能或任何它被称为在角的说法,周围的某个地方。并调用它的对话框中每个需要的实例。

My advice is to do the $compile once, keep the result, the link or transclusion function or whatever it's called in Angular parlance, around somewhere. And call it for each needed instance of the dialog.

这篇关于角 - 可重复使用的对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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