UI路由器嵌套路由控制器不会被调用

编程入门 行业动态 更新时间:2024-10-26 04:25:15
本文介绍了UI路由器嵌套路由控制器不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图调用一个控制器,它应与 home.category 挂钩的路线,但它不会被调用..不知道什么是错的吧。 ?

$ stateProvider                    .STATE(家,{                        //使用的/设置状态为指数的URL。                        网址:/,                        templateUrl:APP_CONFIG.baseUrl +                                '谐音/布局/ home.html做为',                        控制器:'MainCtrl                    })                    .STATE(home.category,{                        //使用的/设置状态为指数的URL。                        网址:C /:的categoryId /:categorySlug                        控制器:函数($ stateParams){                            警报($ stateParams.categoryId);                        }                    })

解决方案

好吧,我发现从 UI路由器的给定资料的线索的说

  

您可以指定一个控制器到您的模板。 警告:控制器不会如果没有定义的模板实例化。

github/angular-ui/ui-router/wiki#controllers

但我尝试添加模板,仍然没有工作,然后我看到我的父路由模板没有< D​​IV UI的视图>< / DIV> (我误拆的话),所以当我说这回它的工作:),所以,实例化我们的孩子的路由控制器,我们必须有<格UI的视图>< / DIV> 在我们父母的路径模板

I am trying to call a controller which should be linked with home.category route but it isn't being called.. don't know what's wrong in it..?

$stateProvider .state("home", { // Use a url of "/" to set a states as the "index". url: "/", templateUrl: APP_CONFIG.baseUrl + 'partials/layouts/home.html', controller: 'MainCtrl' }) .state("home.category", { // Use a url of "/" to set a states as the "index". url: "c/:categoryId/:categorySlug", controller: function($stateParams){ alert($stateParams.categoryId); } })

解决方案

Well, I found a clue from the given documentation of ui-router the says

You can assign a controller to your template. Warning: The controller will not be instantiated if template is not defined.

github/angular-ui/ui-router/wiki#controllers

But I tried to add template and still didn't work, then I saw that my parent route template didn't have <div ui-view></div> (I mistakenly removed it) so when I added it back it worked :), So, to instantiate our child's route controller, we must have <div ui-view></div> in our parent's route template.

更多推荐

UI路由器嵌套路由控制器不会被调用

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

发布评论

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

>www.elefans.com

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