自定义的角度指令内的UI路由器,有意义吗? [英] ui-router inside custom angular directive, make sense?

查看:143
本文介绍了自定义的角度指令内的UI路由器,有意义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,因为它有几个不同的状态孤立的范围自定义指令。
是否有意义,以处理美国使用该指令的内部UI的路由器/ UI的看法?

I'm working on an isolated scope custom directive that has a few different states. Does it make sense to use ui-router/ui-view inside this directive in order to handle the states?

这是一个注意小部件,列出注意事项。如果没有注释,它会显示一个消息,而不是,说他们应该添加注释列表。如果正在装入音符,它表明被加载的注释。如果用户通过点击我上面提到的添加或+增加了一记那么视图是一个文本框。因此,至少有4种不同的看法。

It's a "note widget" that lists notes. If there are no notes, it displays a message instead of the list that says they should add a note. If notes are being loaded, it shows that notes are being loaded. If a user adds a note by clicking the add I mentioned above or the + then the view is a textbox. So there is at least 4 different views.

我最初的直觉是,这将是污染的指令,并给它一个hard依赖于UI的路由器和我的应用程序,因为它定义的状态。我只是担心过?

My initial instinct is that it would be polluting the directive and giving it a hard dependency to ui-router and my application because it defines the states. Am I just over worried?

推荐答案

我会告诉它是这样的:是的,使用 UI路由器,而不是指令 - 用它为您appliation。事实上,你能做的最好是读几篇博客,并通过示例应用程序来理解的原则。你很快就会意识到,没有必要使用的 UI路由器的部分。

I would tell it this way: yes, use the ui-router, but not for a directive - use it for your appliation. In fact, the best you can do is to read few blog posts and go through sample application to understand the principles. You'll soon realize, that there is no need to use the ui-router partially..

基础知识使用UI的路由器AngularJS (乔尔钩子)的

... UI路由器完全包含了一个路由系统的状态机的性质。它允许你定义状态,和过渡您的应用程序的国家。真正的胜利是,它允许你去耦嵌套的状态,并以优雅的方式做了一些非常复杂的布局。

...ui-router fully embraces the state-machine nature of a routing system. It allows you to define states, and transition your application to those states. The real win is that it allows you to decouple nested states, and do some very complicated layouts in an elegant way.

您需要考虑您的不同路由一点,但一旦你周围的基于状态的方法你的头,我想你会喜欢它...

You need to think about your routing a bit differently, but once you get your head around the state-based approach, I think you will like it...

和与UI的路由器在这里 AngularJS状态管理(由本施瓦茨)

and here AngularJS State Management with ui-router (by Ben Schwartz)

...关于AngularJS的新路由器最有趣的事情,是不是路由器本身,而是其附带的状态管理。相反,针对控制器/视图渲染对于一个给定的URL,你的目标的状态。各国在层次结构管理提供父状态和页面组件的成分复杂,都在大自然中,而其余的声明...继承

...The most interesting thing about AngularJS's new router, isn't the router itself, but the state manager that comes with it. Instead of targeting a controller/view to render for a given url, you target a state. States are managed in a heirarchy providing inheritance of parent states and complex composition of page components, all the while remaining declarative in nature...

这里我放在一起的所有链接,最新的,针对样本为例,最有趣code段sample.js ..

Here I put together all the links, up to date, targeting the sample example, the most interesting code snippet sample.js..

摘要后,尝试实现应用程序级别的UI路由器。指令可以再由导体只,帮助你的用户浏览,以国家间穿行......

Summary, try to implement the ui-router on the application level. Directive could then by a conductor only, helping your users to navigate, to walk through among states...

这篇关于自定义的角度指令内的UI路由器,有意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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