javascript - Angular 导入语句中点(.)的含义是什么

标签 javascript angular ecmascript-6

我是 Angular 2 的新手,遵循 Angular 2 快速入门指南。 我想了解 angular app 的目录结构。我正在使用 npm 构建应用程序。 我遇到了 Angular 2 中的导入语句

例如

import {NgModule} from '@angular/core';

我发现它是 sytemjs.config.js 文件,映射为

'@angular/core': 'npm:@angular/core/bundles/core.umd.js'

在哪里

'npm:': 'node_modules/'

npm: 是 node_module 文件夹的别名。

但是当我使用我的自定义组件(由用户制作)并像这样导入时

import {AppComponent} from './app.component';

这里的点(.)代表什么,是代表app文件夹映射为

app: 'app',

最佳答案

点与angular无关,它只是表示当前目录。

例如,如果你有两个这样的文件

app
  file1.js
  file2.js

然后在 app/file1.js 中:

import './file2'

这将告诉您的模块加载器在 app 目录中查找 file2.js,因为那是 file1.js 的当前目录.

您还可以使用 .. 查看父目录。

这是来自 dot definition 的一个很好的解释, 从 Rahul Tripathi 获得:

On Unix-like operating systems every directory contains, as a minimum, an object represented by a single dot and another represented by two successive dots. The former refers to the directory itself and the latter refers to its parent directory (i.e., the directory that contains it). These items are automatically created in every directory, as can be seen by using the ls command with its -a option (which instructs it to show all of its contents, including hidden items).

关于javascript - Angular 导入语句中点(.)的含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40446024/

相关文章:

javascript - iframe 中的页面宽度

来自浏览器桌面通知点击事件的 Angular 6 路由产生意外行为

html - *ngIf=item.activityStatus!= ("Done") 作为 angular2 条件可见性

angular - 为什么这个 Angular 应用程序无法处理用户登录后更改显示内容的用户状态(登录\注销)?

javascript - 有人可以向我解释这个 es6 语法吗?

javascript - ES6 代理设置属性陷阱不触发数组长度

javascript - 迭代 react 组件

javascript - 打包具有依赖项的浏览器/服务器 CommonJS 模块

javascript - url 中的字符串部分需要正则表达式

javascript - 在 FabricJS 中删除多个路径