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

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

问题描述

我正在研究具有几种不同状态的独立作用域自定义指令.在此指令中使用 ui-router/ui-view 来处理状态是否有意义?

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.

我最初的直觉是它会污染指令并使其对 ui-router 和我的应用程序产生严重依赖,因为它定义了状态.我是不是太担心了?

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-router,但不要用于指令 - 将它用于您的应用程序.事实上,你能做的最好的事情就是阅读一些博客文章并通过示例应用程序来理解原理.您很快就会意识到,无需部分使用 ui-router..

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..

来自 在 AngularJS 中使用 ui-router 的基础(作者:Joel Hooks)

from The basics of using ui-router with AngularJS (by Joel Hooks)

...ui-router 完全包含路由系统的状态机特性.它允许您定义状态,并将您的应用程序转换为这些状态.真正的优势在于它允许您解耦嵌套状态,并以优雅的方式进行一些非常复杂的布局.

...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...

和这里 AngularJS 状态管理与 ui-路由器 (本·施瓦茨着)

...关于 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...

这里我把所有链接放在一起,最新的,针对示例,最有趣的代码片段 sample.js..

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

总结,尝试在应用层面实现ui-router.指令只能由指挥员执行,帮助您的用户导航,在状态之间穿行......

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-router,有意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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