2016-02-29 71 views
0

我是新来的角游,背景是服务器端Java,.net等超越的英雄

所以,我完成了英雄之旅,我已经创建了简单的硬编码的多页应用。现在我需要进入下一步并调用服务器通过rest/JSON调用来检索数据。基于该AngularJS例如: https://angular.io/docs/ts/latest/guide/server-communication.html

和一些其他的博客,如: http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html

我拥有它应该是怎样一个很好的了解工作。但是,我现在看到两个错误: 在浏览器中:无法解析'AuthService'(?)的所有参数。确保所有参数都用Inject装饰或具有有效的类型注释,并且'AuthService'用Injectable装饰。

和NPM: 应用程序/ auth.service.ts(9,19):错误TS2304:找不到名称 'HTTP'。

我不知道如何追逐依赖关系。 packages.json? typings.json,tsconfig.json ...或者它们是如何工作的;我找不到任何文件;有什么建议么?

auth.service:

import {Injectable} from 'angular2/core'; 
import {HTTP_PROVIDERS} from 'angular2/http'; 

@Injectable() 
export class AuthService { 
    items:Array<any>; 

    constructor(http:Http) { 

    } 
} 

main.ts

import {bootstrap} from 'angular2/platform/browser' 
import {AppComponent} from './app.component' 

import {HTTP_PROVIDERS} from 'angular2/http'; 
import { AuthService } from './auth.service'; 

bootstrap(AppComponent, [HTTP_PROVIDERS, AuthService]); 

我没有在一个组件所消耗的Auth.Service呢。

回答

0

我认为这个问题是你是不是在HTTP中拉,只是HTTP_PROVIDERS,在你auth.service试试这个

import {Http} from 'angular2/http' 
+0

摩根,仅此而已。任何关于如何追查依赖关系的指针?我还没有找到任何关于它如何拼凑在一起的解释。 –

+0

现在很难,因为即使网站上的文档不完整。帮助我解决问题的是使用一个好的IDE,我使用IntelliJ使用pycharm,它几乎总是告诉我什么时候我没有正确导入某些东西。否则,最好的选择是去https://angular.io/docs/ts/latest/api/#!?apiType=Class这些类是一个巨大的列表,我认为所有的依赖关系,问题不是所有的他们是最新的或甚至写入。我会说在Angular2的stackoverflow上有3个人是很棒的资源,并且很快就会做出反应。蒂埃里,冈特和马克。 –

+0

谢谢。蒂姆S –