Angularjs + typescript控制器解决了麻烦

时间:2013-08-14 14:50:23

标签: javascript angularjs typescript

此脚本

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

给我这个错误

错误:未知提供者:albumsProvider< - albums

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(专辑);所以

我等着拿相册

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

只有上述错误:(

我真的不知道转向哪种方式

你可以给我一个提示吗?

谢谢

1 个答案:

答案 0 :(得分:0)

更新的答案 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 */
    }

Playground