从angularjs,最佳实践的孩子的状态视图中隐藏父状态有何看法? [英] Hiding parent state view from child state view in angularjs, best practices?

查看:145
本文介绍了从angularjs,最佳实践的孩子的状态视图中隐藏父状态有何看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新批准的产品,广告活动的广告这就是'产品campaigns.product-活动细节当我打电话通过UI的SREF父状态视图状态子子状态获取与孩子的状态视图一起被称为我不想要的。我只希望孩子的状态视图。

'update-approved-product-campaign-ad' this is the child state of 'product-campaigns.product-campaign-detail' when i call child state through ui-sref parent state view gets called along with child state view which i don't want. I want only child state view.

推荐答案

这可以通过使用视图目标完成。

This can be done using view targeting.

假设你有一位不愿透露姓名的用户界面视图在根父。当孩子被激活,它可以使用有针对性的意见接管父母的未命名视图。子视图可以直接把自己的内容放到父母的观点:

Say you have an unnamed ui-view for the parent at the root. When the child is activated, it can take over the parent's unnamed view using targeted views. The child view can put its own content directly into the parent's view:

var app = angular.module("plunker", ['ui.router'])
app.config(function($stateProvider) {
  $stateProvider.state('parent', {
    url: "",
    template: "<a ui-sref='.child'>Go to child</a><h1>Parent</h1>"
  }).state('parent.child', {
    url: '/child',
    views: {
      "@": {
        template: "<a ui-sref='^'>Back to parent</a><h1>child</h1>"
      }
    }
  })
})

或者它可能取代,只是有一个嵌套的UI视图,模板父视图,它又将目标

or it could replace the parent view with a template that just has a nested ui-view, which it in turn targets

var app = angular.module("plunker", ['ui.router'])
app.config(function($stateProvider) {
  $stateProvider.state('parent', {
    url: "",
    template: "<a ui-sref='.child'>Go to child</a><h1>Parent</h1>"
  }).state('parent.child', {
    url: '/child',
    views: {
      "@": {
        template: "<small>parent ui-view overridden by parent.child</small> <div ui-view='child'/>"
      },
      "child@parent.child": {
        template: "<a ui-sref='^'>Back to parent</a><h1>child</h1>"
      }
    }
  })
})

目标命名视图是视图名@ Statename的。命名视图@是指目标命名为空字符串()的观点,在(@)根的状态()。

Targeted named views are "viewname@statename". The named view "@" means target the view named empty string ("") at (@) the root state ("").

<一个href=\"http://plnkr.co/edit/iff63xbNWCbK9MEPMb4f?p=$p$pview\">http://plnkr.co/edit/iff63xbNWCbK9MEPMb4f?p=$p$pview

这篇关于从angularjs,最佳实践的孩子的状态视图中隐藏父状态有何看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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