angularjs UI路由器默认的孩子的状态和UI,SREF [英] angularjs ui-router default child state and ui-sref

查看:294
本文介绍了angularjs UI路由器默认的孩子的状态和UI,SREF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的状态在我的UI路由器状态提供:

I have the following states in my ui-router state provider:

$urlRouterProvider.when('/parent', '/parent/child');
$stateProvider.state('parent', {
     url: "/parent",
     abstract: true
});

$stateProvider.state('parent.child', {
     url: "/child"
});

它遵循最佳做法有一个默认的子状态解释<一个href=\"https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-set-up-a-defaultindex-child-state\">here在UI路由器文档。

然而,当我现在还包括我的文档中的链接的地方引用父与 UI-SREF &LT;一个UI的SREF =家长&GT;链接&LT; / A&GT; 我总是得到一个错误,说我不能过渡到一个抽象的状态。当我手动输入网址到地址栏并回车一切工作正常。

However, when I now include a link in my document somewhere referencing parent with ui-sref such as <a ui-sref="parent">Link</a> I always get an error saying I cannot transition to an abstract state. When I enter the URL manually into the address bar and hit enter everything works fine.

相关Plunker:<一href=\"http://plnkr.co/edit/d3Z0tOwC3VCTPqGiB0df?p=$p$pview\">http://plnkr.co/edit/d3Z0tOwC3VCTPqGiB0df?p=$p$pview

我如何能结合 UI-SREF 默认状态子?

How can I combine ui-sref with default child states?

推荐答案

抽象状态不能直接针对性。他们主要作为建立在孩子状态的基础。它工作正常的URL的唯一原因是,/ Parent获取的。当抓到

abstract states can not be targeted directly. They mainly serve as a foundation to build child states on. The only reason it works fine with the URL is that the /parent gets caught by the .when

这是当你使用调用一个孩子意味着

That means when you invoke a child using

<a ui-sref="parent.child">

父里面孩子被载入,这意味着母公司将被载入因为它周围的层。

the child inside the parent gets loaded, meaning the parent will be loaded as the layer around it.

所以,从来没有针对抽象的国家本身。这就像一个门框内的门。你只能打开和同门(子)相互作用,但从未直接与框架(父)。然而,当你同门互动,门和框架是被加载到系统的一部分。

So, never target an abstract state itself. It's like having a door inside a door frame. You can only open and interact with the door (child), but never with the frame (parent) directly. However, when you interact with the door, the door and the frame are part of a system that gets loaded.

您可以给孩子一个空的URL,因此,它不附加任何母公司状态和URL将被载入。

You can give the child an empty URL, so that it doesn't append anything to the parent state URL and will then be loaded.

在这里看到更多的信息:
<一href=\"https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states\">https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states

See here for more info: https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states

这篇关于angularjs UI路由器默认的孩子的状态和UI,SREF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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