我是 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/