AngularUI:为什么模态不作为指令? [英] AngularUI: why modal is not implemented as a directive?

查看:159
本文介绍了AngularUI:为什么模态不作为指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用了棱角分明的UI在我的项目,我想实现一个模态窗口。大多数库组成部分的( http://angular-ui.github.io/bootstrap/)实现为指令(如预期)。然而,模态是不 - 它被实现为服务。这导致在控制器上的视图强依赖性(即,控制器需要知道该视图使用一个模式窗口,应该不会是这样)。

I am using angular-ui in my project and I wanted to implement a modal window. Most of the components of the library (http://angular-ui.github.io/bootstrap/) are implemented as directives (as expected). However, modal is not - it is implemented as a service. This leads to a strong dependency on the view in the controller (i.e. the controller needs to know that the view uses a modal window, what should not be the case).

我的问题是:为什么模式实现为服务,而不是指令?它是否给什么好处?

My question is: why is modal implemented as a service, not directive? Does it give any benefits?

推荐答案

$模式指令是相当灵活,并且通过它的API,它支​​持:

The $modal directive is quite flexible, and by its API, it supports:


  • 会被触发你想无论如何,由于打开时的控制器控制。

  • 从控制器将数据传递到对话框中的控制器,使用决心选项

  • 使用在对话框中的任何控制器或模板。

  • 从对话框上接近触发控制器将数据传递回来,它的结果的承诺。

  • Being triggered on any event you want, since the controller controls when it opens.
  • Passing data from the controller to the controller in the dialog, using the resolve option
  • Using any controller or template in the dialog.
  • Passing data back from the dialog on close to the triggering controller, by its result promise.

虽然不是不可能的这一切在一个指令,我认为这可能只是现实使用很多的选择,还是一个复杂的对象,这在该控制器将建造反正来实现。

While not impossible for this to all be in a directive, I think it could only realistically be achieved by using a lot of options, or a complicated object, which would have to be constructed in the controller anyway.

另一个原因这不是一个指令,是指示通常是用于在页面的特定位置的事情。由于其本身的设计模态不附加到网页中的任何元素。

Another reason for this not being a directive, is that directives are usually for things in a particular place in a page. The modal by its very design is not attached to any element in the page.

我建议尝试设计了一个指令,让相同的功能 $模式的API,我怀疑它会显示,使用服务,对整体而言,更清晰,而且可能更加灵活。

I would suggest trying to design an API for a directive that gives the same functionality as $modal, and I suspect it'll reveal that using a service is, on the whole, clearer, and probably more flexible.

这篇关于AngularUI:为什么模态不作为指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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