【问题标题】:ui-sref set child view to parent viewui-sref 将子视图设置为父视图
【发布时间】:2015-07-21 18:49:58
【问题描述】:

我根据状态使用 ui-sref 进行路由。 目前,我在父级中获取孩子的视图作为层次结构。我想将孩子的视图分配给父视图。当前状态如下plunker

[链接][//plnkr.co/edit/fpsTWglicbcGMotJIlll]

我想在点击点击我后看到欢迎。

【问题讨论】:

  • 您的 js 文件中没有任何代码,请在 Stack Overflow 上分享您的代码。 stackoverflow.com/help/how-to-ask
  • 你能包含一些代码吗?
  • 我无法添加超链接 ..我正在添加纯 URL 。

标签: angularjs angularjs-routing ui-sref


【解决方案1】:

如果我正确理解了您的问题,那么问题是您有 inner 作为 tab1 的孩子...所以它显示在 tab1 的 ui 视图中。如果你想让它代替tab1,那么你不需要tab1中的ui-view。

这是一个分叉的 plunker,显示了我的意思。

http://plnkr.co/edit/t4cxejVLGf4kywKp2bb5?p=preview

我改变的部分:

.state("main", { abtract: true, url:"/main", templateUrl:"main.html" })
.state("main.tab1", { url: "/tab1", templateUrl: "tab1.html" })
.state("main.inner",{
  url:"/inner",
  templateUrl:"inner.html"
})
.state("main.tab2", { url: "/tab2", templateUrl: "tab2.html" })

在tab1.html中

<div>
    This is the view for tab1
    <a ui-sref="main.inner">click me</a>
</div>

这就是你的目标吗?

【讨论】:

  • 谢谢 ..我会将它与我的模块合并。
【解决方案2】:

在控制器中添加$scope.$state = $state;

然后将ng-hide="$state.current.name === 'main.tab1.inner'"添加到

 <h2 ng-hide="$state.current.name === 'main.tab1.inner'">View:</h2>

<div ng-hide="$state.current.name === 'main.tab1.inner'">
This is the view for tab1
<a ui-sref="main.tab1.inner">click me</a>
</div>

这是链接[链接]http://plnkr.co/edit/Yvlp6RNF69yiSq1HfMcf?p=preview

【讨论】:

  • 感谢您的努力和时间,这看起来也不错,但我正在寻找类似@DWDuck 提到的东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多