问题描述
我试图调用一个应该与 home.category
路由链接的控制器,但它没有被调用.有什么问题吗?
$stateProvider.state(家",{//使用/"的 url 将状态设置为索引".网址:/",模板网址:APP_CONFIG.baseUrl +'部分/布局/home.html',控制器:'MainCtrl'}).state("home.category", {//使用/"的 url 将状态设置为索引".url: "c/:categoryId/:categorySlug",控制器:函数($stateParams){警报($stateParams.categoryId);}})
好吧,我从 ui-router
的给定文档中找到了一个线索
您可以为模板分配一个控制器.警告:如果没有定义模板,控制器将不会被实例化.
https://github.com/angular-ui/ui-router/wiki#controllers一个>
但是我尝试添加template
还是不行,然后我看到我的父路由模板没有<div ui-view></div>
(我错误地删除了它)所以当我重新添加它时它起作用了:),所以,为了实例化我们孩子的路由控制器,我们必须有
code> 在我们父母的路由模板中.
I am trying to call a controller which should be linked with the home.category
route but it isn't being called. 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
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-router 嵌套路由控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!