1

I have changed my angular 2 app to RC. It worked fine until i included HTTP_PROVIDER and created service.ts.

I get an error

(index):14 Error: SyntaxError: Unexpected token <(…)

and i cant seem to discover why. Can anyone help with this ?

This is my service.ts code

    /**
 * Created by Adjoa on 5/29/2016.
 */
import {Injectable} from  "@angular/core";
import {Http,Headers,HTTP_PROVIDERS} from "@angular/http";
import { Headers, RequestOptions } from '@angular/http';

@Injectable()

export class SignInService {
    constructor(private _http: Http){}

    postData(data:any){
        const body = JSON.stringify(data);
        const headers= new Headers();
        headers.append('Content-Type','application/json');
        return this._http.post('https://testing-angular-2.firebaseio.com/datatest.json', body, {headers:headers});
    }
}
Adjoa Wadee
  • 109
  • 1
  • 5
  • 12

1 Answers1

3

Most of the time you have this error when SystemJS can't load a module. A 404 error is behind this message.

I think that you forgot to add the @angular/http entry into your SystemJS configuration:

var map = {
  'app': 'app', // 'dist',
  'rxjs': 'node_modules/rxjs',
  '@angular': 'node_modules/@angular'
};

var packages = {
  'app': { main: 'main.js',  defaultExtension: 'js' },
  'rxjs': { defaultExtension: 'js' }
};

var packageNames = [
  '@angular/common',
  '@angular/compiler',
  '@angular/core',
  '@angular/http', // <------
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',
  '@angular/router',
  '@angular/router-deprecated',
  '@angular/testing',
  '@angular/upgrade',
];

packageNames.forEach(function(pkgName) {
  packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});

var config = {
  map: map,
  packages: packages
}
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360