UI路由器嵌套路由控制器不会被调用 [英] ui-router nested route controller isn't being called
问题描述
我试图调用一个控制器,它应与 home.category
挂钩的路线,但它不会被调用..不知道什么是错的吧。 ?
$ stateProvider .STATE(家,{
//使用的/设置状态为指数的URL。
网址:/,
templateUrl:APP_CONFIG.baseUrl +
'谐音/布局/ home.html做为',
控制器:'MainCtrl
})
.STATE(home.category,{
//使用的/设置状态为指数的URL。
网址:C /:的categoryId /:categorySlug
控制器:函数($ stateParams){
警报($ stateParams.categoryId);
}
})
好吧,我发现从 UI路由器的给定资料的线索
的说
您可以指定一个控制器到您的模板。 警告:控制器不会如果没有定义的模板实例化。
块引用><一个href=\"https://github.com/angular-ui/ui-router/wiki#controllers\">https://github.com/angular-ui/ui-router/wiki#controllers
但我尝试添加
模板
,仍然没有工作,然后我看到我的父路由模板没有&LT; DIV UI的视图&gt;&LT; / DIV&GT;
(我误拆的话),所以当我说这回它的工作:),所以,实例化我们的孩子的路由控制器,我们必须有&LT;格UI的视图&gt;&LT; / DIV&GT;
在我们父母的路径模板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 saysYou can assign a controller to your template. Warning: The controller will not be instantiated if template is not defined.
https://github.com/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路由器嵌套路由控制器不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!