【问题标题】:How to find the namespace to import from for Angular 2?如何找到要从 Angular 2 导入的命名空间?
【发布时间】:2015-12-22 17:01:36
【问题描述】:

全部:

我对 ES6/TYPESCRIPT/Angular2 很陌生,当我浏览 Angular2 官方网站的教程时,首先让我感到困惑的是:

import {Component} from 'angular2/core';

我的问题是:

“angular2/core”是什么?那是一个模块目录吗?还是只是一个命名空间字符串?当我使用组件或模块时,如何/在哪里找到这部分?

谢谢

【问题讨论】:

    标签: angular


    【解决方案1】:

    您可能想先从 doc 阅读这部分 this

    import {AppComponent} from './app.component'; import 语句告诉系统它可以从中获取 AppComponent 位于相邻文件中的名为 app.component 的模块。模块 名称(AKA 模块 id)通常与没有文件名的文件名相同 扩展名。

    this

    module-name:要导入的模块的名称。这是一个文件名。

    应该是一个叫做core.js的文件,也就是here

    而且由于模块名和文件名相同,所以你可以看到它来自一个名为core的模块。

    在哪里可以找到这个?

    例如,如果您想使用 http 服务。

    在文档api中查找

    https://angular.io/docs/ts/latest/api/

    http 位于 angular2/http 部分

    我认为这是一个很好的线索,您应该从 angular2/http 导入它

    【讨论】:

    • 谢谢,我会按照这个深入研究。
    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 2012-04-03
    • 2014-12-02
    • 1970-01-01
    相关资源
    最近更新 更多