孩子的路线不触发

编程入门 行业动态 更新时间:2024-10-07 08:25:31
本文介绍了孩子的路线不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我建立这条路线系统

var app = angular.module('plunker', ['ui.router']); app.config(function ($stateProvider, $urlRouterProvider) { $urlRouterProvider .when('/admin', '/admin/dashboard') .when('/user', '/user/dashboard') .otherwise('/admin/dashboard'); $stateProvider .state('admin', { url: '/admin/dashboard', resolve: { test: function() { console.log('called admin'); return; } }, views: { 'navigation': { template: '<div>admin navigation. Go <a ui-sref="admin.link1">link1</a></div>' }, 'content': { template: '<div>admin dashboard</div>' } } }) .state('admin.link1', { //for some reason admin.link1 does not work but just link1 is OK url: '/admin/link1', resolve: { test: function() { console.log('admin.link1 called resolve'); return; } }, views: { 'navigation': { template: '<div>admin navigation</div>' }, 'content': { template: '<div>admin link1</div>' } } }) .state('user', { url: '/user/dashboard', views: { 'navigation': { template: '<div>user navigation</div>' }, 'content': { template: '<div>user dashboard</div>' } } }); });

的HTML将导航和内容 用户界面视图它

<body ng-app="plunker"> <div> <a ui-sref="admin">Admin</a> <a ui-sref="user">User</a> </div> <div ui-view="navigation"></div> <div ui-view="content"></div> </body>

我要点击链接1 并转到 admin.link1 状态,但不知何故,这是行不通的。

I want to click on link1 and go to admin.link1 state but somehow that is not working.

但是,如果我删除管理​​父,并使用链接1 而已,它工作正常。

But if I remove the admin parent and use link1 only, it works fine.

code: plnkr.co/edit/F7lw58esXz7rWzeo3ER6? p = preVIEW

preVIEW: embed.plnkr.co/F7lw58esXz7rWzeo3ER6/$p $ PVIEW

任何线索?

推荐答案

您几乎在那里,更新的 plunker 。世界上只有一个变化嵌套观点确实有附加标志的'@'

You were almost there, the updated plunker. There is only one change the nested views do have appended sign '@':

.state('admin.link1', { url: '/admin/link1', resolve: { test: function() { console.log('admin.link1 called resolve'); return; } }, views: { // instead of this // 'navigation': { // we have to use absolute name with the @ at the end 'navigation@': { template: '<div>admin navigation</div>' }, // this is searched in parent view // 'content': { // this is targting the root 'content@': { template: '<div>admin link1</div>' } } })

问题的关键是隐藏在绝对视图命名,摘录:

在幕后,每一个观点被分配遵循的方案绝对名称 视图名@ Statename的 ,其中视图名是所使用的名称view指令和国家名称是国家的绝对名称,例如: contact.item。您也可以选择在绝对语法来写你的视图名称。

Behind the scenes, every view gets assigned an absolute name that follows a scheme of viewname@statename, where viewname is the name used in the view directive and state name is the state's absolute name, e.g. contact.item. You can also choose to write your view names in the absolute syntax.

该工作示例(S)这里或其他的这里

The working example(s) here or other here

的请尝试读取这个回答,在那里我试着深深描述什么是视图命名的。 (搜索最后一节:扩展:给的答案评论)的

Please, try to read this answer, where I tried deeply describe what is the view naming about.(search for a last section: EXTEND: to give THE answer to a comment)

更多推荐

孩子的路线不触发

本文发布于:2023-11-25 21:34:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631433.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路线   孩子

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!