How to import other modules in Angular 2? -
i tried use angular2/http module within angular 2 app, when try import system.src.js throws error http:///angular2/http 404 not found.
heres how index.html looks like:
<html> <head> <title>angular 2 quickstart</title> <!-- 1. load libraries --> <script src="angular2/bundles/angular2-polyfills.js"></script> <script src="systemjs/dist/system.src.js"></script> <script src="rxjs/bundles/rx.js"></script> <script src="angular2/bundles/angular2.dev.js"></script> <!-- 2. configure systemjs --> <script> system.config({ packages: { app: { format: 'register', defaultextension: 'js' } } }); system.import('app/boot') .then(null, console.error.bind(console)); </script> <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet"> <link href="assets/styles/main.css" rel="stylesheet"> </head> <!-- 3. display application --> <body> <my-app>loading...</my-app> </body> </html> boot.ts
import {bootstrap} 'angular2/platform/browser' import {appcomponent} './app.component' bootstrap(appcomponent); the component try import http:
import {injectable} 'angular2/core'; import {track} './track' import {http, headers} 'angular2/http'; @injectable() export class actiontracker { constructor(private _http : http){} login(){ this._http.post('/api/login', "") .map(res => res.json()) .subscribe( data => console.log(data), err => console.log(err), () => console.log('authentication complete') ); } } would great if explain how make import work. tried import third party lib before failed too.
thanks help.
include http.dev.js in index.html
<script src="angular2/bundles/http.dev.js"></script>
Comments
Post a Comment