我试图调用一个控制器,它应与 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
但我尝试添加模板,仍然没有工作,然后我看到我的父路由模板没有< DIV 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路由器嵌套路由控制器不会被调用
发布评论