angular2 – Angular 2没有提供商Http

前端之家收集整理的这篇文章主要介绍了angular2 – Angular 2没有提供商Http前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我得到的EXCEPTION:没有提供商Http!在我的Angular 2.我做错了什么?
  1. import {Http,Headers} from 'angular2/http';
  2. import {Injectable} from 'angular2/core'
  3.  
  4.  
  5. @Component({
  6. selector: 'greetings-ac-app2',providers: [],templateUrl: 'app/greetings-ac2.html',directives: [NgFor,NgModel,NgIf,FORM_DIRECTIVES],pipes: []
  7. })
  8. export class GreetingsAcApp2 {
  9. private str:any;
  10.  
  11. constructor(http: Http) {
  12.  
  13. this.str = {str:'test'};
  14.  
  15. http.post('http://localhost:18937/account/registeruiduser/',JSON.stringify(this.str),{
  16. headers: new Headers({
  17. 'Content-Type': 'application/json'
  18. })
  19. });
  1. import { HttpModule } from '@angular/http';
  2.  
  3. @NgModule({
  4. imports: [ BrowserModule,HttpModule],declarations: [ AppComponent ],bootstrap: [ AppComponent ]
  5. })
  6. export default class AppModule { }
  7.  
  8. platformBrowserDynamic().bootstrapModule(AppModule);

理想情况下,您将这个代码分成两个单独的文件
详情请:

> https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html
> https://angular.io/docs/ts/latest/guide/ngmodule.html

猜你在找的Angularjs相关文章