路过的决心结果到控制器UI的路线 [英] Passing result of resolve into controller with UI-Route

查看:97
本文介绍了路过的决心结果到控制器UI的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何使用解决了UI的路由器,我认为有一件我缺少的信息,因为我无法弄清楚如何使他们的工作。

I'm trying to learn how to use resolves with UI-Router, and I think there's a piece of information I'm missing, because I can't figure out how to make them work.

我已经设置这样的状态:

I have a state set like this:

app.config(['$stateProvider', function($stateProvider) {
    $stateProvider
        .state('testState', {
            url: '/testRoute',
            controller: 'TestContoller',
            views: {
                "body": { 
                    templateUrl: "testHtml.html" 
                }
             },
            resolve: {
                test:  function(){
                    return {value: "test"};
                 }
            }
        })      
}]);

然后,我有一个控制器:

And then I have a controller:

app.controller("TestController", ["$scope", "test", function($scope, test) {
    console.log(test);
}]);

然后我有没有在那一刻有什么在testHtml.html部分文件:

then I have a testHtml.html partial file that doesn't have anything in at the moment:

<div ng-controller="TestController">
Test content
</div>

这将载入index.html中的用户界面视图:

And that gets loaded into the ui-view in index.html:

<div ui-view="body" autoscroll></div>

我一直在这个四处摆弄了一小时左右,现在谷歌上搜索周围,我不能完全弄清楚什么我应该做的,以获得决心做一些事情并将结果传递到控制器。

I've been fiddling around with this for an hour or so now and googling around and I can't quite figure out what I should be doing to get the resolve to do something and pass the result into the controller.

推荐答案

当你提到的意见态性质级别选项,它忽略了 templateUrl &安培; 控制器上的状态。它只能采取控制器和放大器; 模板/ templateUrl 但从之一。

When you mention views properties on state level options, it ignores templateUrl & controller on that state. It only take controller & template/templateUrl from one of view.

code

views: {
   "body": { 
      templateUrl: "testHtml.html",
      controller: 'TestContoller' //moved it to named-view level
   }
},

这篇关于路过的决心结果到控制器UI的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆