2016-10-10 3 views
0

HTTPリクエストを送信するためにそのボタンを使用するために、動作中のボタンでWebページを取得しようとしています。私は角のHTTPをインストールし、モジュールで宣言しました。これは私がNG2はコンストラクタ(http:Http)、予期しないトークンでビルドされません。

import { Component } from '@angular/core'; 
import { Injectable } from '@angular/core'; 
import { Http } from '@angular/http'; 

@Component ({ 
    selector: 'buttonTest', 
    template: ` 
    <button (click)='clicked($event)'>Test Button</button> 
    ` 
}) 
@Injectable() 
export class LoadButton { 
    constructor(private http: Http) { 
    } 
    clicked(event) { 
    console.log(this.http.get) 
    } 
} 

システムの設定は、いくつかのスタックオーバーフローの記事で言及されているエラーを引き起こし

11 | @Injectable() 
    12 | export class LoadButton { 
> 13 | constructor(private http: Http) { 
    |      ^
    14 | } 
    15 | clicked(event) { 
    16 |  console.log(this.http.get) 

npm ERR! Linux 4.4.0-38-generic 
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build" 
npm ERR! node v6.7.0 
npm ERR! npm v3.10.3 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] build: `babel src -d app` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] build script 'babel src -d app'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the random-quote package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  babel src -d app 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs random-quote 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls random-quote 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /home/drew/Dropbox/js/sideProjs/redditTime/npm-debug.log 

ファイルを取得エラーですが、正しくないではないようです

(function() { 
    // map tells the System loader where to look for things 
    var map = { 
    'app': 'app', 
    '@angular': 'node_modules/@angular', 
    'rxjs': 'node_modules/rxjs' 
    }; 
    // packages tells the System loader how to load when no filename and/or no extension 
    var packages = { 
    'app': { main: 'main.js', defaultExtension: 'js' }, 
    'rxjs': { defaultExtension: 'js' } 
    }; 
    var ngPackageNames = [ 
    'common', 
    'compiler', 
    'core', 
    'forms', 
    'http', 
    'platform-browser', 
    'platform-browser-dynamic', 
    'router' 
    ]; 
    ngPackageNames.forEach(function(pkgName) { 
    packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' }; 
    }); 
    var config = { 
    map: map, 
    packages: packages 
    }; 
    System.config(config); 
})(); 

アイデア私はこのエラーを引き起こしていることを逃したか分からない。

答えて

0

あなたの角張ったバージョンは何ですか?

輸入はHttpModuleをNgModule宣言

import {BrowserModule} from '@angular/platform-browser'; 
 
import {NgModule} from '@angular/core'; 
 
import {HttpModule} from '@angular/http'; 
 
import {AppComponent} from './app.component'; 
 

 
@NgModule({ 
 
    declarations: [ 
 
    AppComponent, 
 
    ], 
 
    imports: [ 
 
    BrowserModule, 
 
    HttpModule, 
 
    ], 
 
    providers: [ 
 
    ], 
 
    bootstrap: [AppComponent] 
 
}) 
 
export class AppModule { 
 
}

+0

角度2.0.1で、私は二重の私のモジュールをチェックして、私たちは同じことを持っています – drew4452862

関連する問題