1

这个脚本

https://gist.github.com/whisher/6231714

给我这个错误

错误:未知的提供者:专辑提供者 <- 专辑

this.app.config(($routeProvider:ng.RouteProvider) => { 
            $routeProvider.
                    when('/', {
                        templateUrl: './view.html', 
                        resolve: {
                            albums: function(Album) {
                               console.log(Album);
                                return Album.getResource().query();
                            }
                        },
                        controller: 'AlbumController',
                        })

           } ); 
class AlbumController {
    constructor (private $scope,private albums) {
        this.$scope.test = '20 whatsomething';
        this.$scope.albums = albums;
    }
}

专辑在范围内 console.log(Album); 所以

我等着拿专辑

在我的控制器中,但我得到了

只有上述错误:(

我真的不知道该转向哪个方向

你能给我一个提示吗?

谢谢

4

1 回答 1

0

更新的 Answer Angular 只能依赖注入你注册的东西。既然你有

this.app.service ('Album',Album);

您只能请求Album而不是album. 所以修改你的构造函数:

constructor (private $scope,private albums) {
    this.$scope.test = '20 whatsomething';
    this.$scope.albums = albums;
}

至:

    // You can only get variables injected that you registered with angular: 
    constructor (private $scope,private Album) {
        this.$scope.test = '20 whatsomething';

        this.$scope.albums = Album.getResource(). /* Send your request based on http://docs.angularjs.org/api/ngResource.$resource */
    }

操场

于 2013-08-14T19:15:26.773 回答