如何在Angular 2中导入其他模块? [英] How to import other modules in Angular 2?

查看:100
本文介绍了如何在Angular 2中导入其他模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Angular 2应用程序中使用Angular2/http模块,但是当我尝试将其导入时,system.src.js抛出错误http:///angular2/http 404 not found.

I tried to use the Angular2/http module within my Angular 2 app, but when I try to import it system.src.js throws an error http:///angular2/http 404 not Found.

这是我的index.html的样子:

Heres how my 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 the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>

boot.ts

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

bootstrap(AppComponent);

我尝试导入http:

import {Injectable} from 'angular2/core';
import {Track} from './track'
import {Http, Headers} from '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 be great if anyone could explain how to make the import work. I also tried to import a third party lib before where I failed too.

感谢您的帮助.

推荐答案

在您的index.html中包含http.dev.js

Include http.dev.js in your index.html

<script src="angular2/bundles/http.dev.js"></script>

这篇关于如何在Angular 2中导入其他模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆