AngularJS,决心和未知的供应商 [英] AngularJS, resolve and unknown provider

查看:104
本文介绍了AngularJS,决心和未知的供应商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两条路线与决心。是这样的:

I've two routes with resolve. Goes like this:

.when('/foos', {
templateUrl: 'views/foos.html',
controller: 'FoosCtrl',
resolve: {
    foo_list: ['$q', '$route', '$timeout', '$location', 'Foos', function($q, $route, $timeout, $location, Foos) {
        // postpone the execution
        var deferred_foo = $q.defer()

        Foos.getFoos({token:session_uid}, successCb)

        function successCb(list) {
            if(list['status'] === 200) {
                deferred_foo.resolve(list)
            }
            else {
                alert('Crashcrashcrash')
                deferred_foo.reject("Something just wasn't right")
                //$location.path('maintenance')
            }
        }
        return deferred_foo.promise
        }]
    }
})
.when('/r/:type/:bar_id', {
    templateUrl: 'views/bar.html',
    controller: 'BarsCtrl',
    resolve: {
        bar: ['$q', '$route', '$timeout', '$location', 'Bars', function($q, $route, $timeout, $location, Bars) {
            // postpone the execution
            var deferred = $q.defer()

            Bars.getBar({type: bar_type}, successCb)    

            function successCb(result) {
                if(result['status'] === 200) {
                    deferred.resolve(result)    
                }
                else {
                    alert('Crashcrashcrash')
                    deferred.reject("Something just wasn't right")
                    $location.path('foos')
                }

                return deferred.promise
                }]
            }
        })

然后我有两个控制器的工作是这样的:

Then I've two controllers working like this:

 App.controller('FoosCtrl', ['$scope', '$location', 'Foos', 'foo_list', function($scope, $location, Foos, foo_list) {...}

 App.controller('BarsCtrl', ['$scope', '$routeParams', '$location', 'Bars', 'bar', 'sharedService', function($scope, $routeParams, $location, Bars, bar, sharedService) {...}

有人能解释为什么酒吧的作品,但美孚给了我错误:未知提供商:foo_listProvider< - foo_list ?我试着用不同的名称替换 foo_list 的情况下,驼峰规则做了一些事,但并没有帮助。

Could somebody explain why Bar works but Foo gives me Error: Unknown provider: foo_listProvider <- foo_list? I've tried replacing foo_list with different name in case camelCasing did something but didn't help.

推荐答案

所以,这个问题是惊人的相似,以我自己的,我只是想出了与在角IRC频道的乡亲的帮助......你是,由偶然的机会,建立你的控制器,虽然 NG-控制器?我有:

So, this question was surprisingly similar to my own which I just figured out with help from the folks over at the Angular IRC channel... are you, by chance, setting up your controller though ng-controller? I had:

    <div ng-controller="myCtrl">

...当它应该已被删除:

... when it should have been removed:

    <div>

...因为我是建立在路由器上的决心控制器。这就是我在做什么,它是造成这一非常问题。你可以看到更多在这里:

... because I was setting up the controller in the resolve on the router. That's what I was doing and it was causing this very issue. You can see more here:

<一个href=\"http://stackoverflow.com/a/18305423/1306982\">http://stackoverflow.com/a/18305423/1306982

这篇关于AngularJS,决心和未知的供应商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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