typescript “@angular/core”中的“@”符号是什么意思?陈述?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37372816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "@" symbol mean in "import { Component } from '@angular/core';" statement?
提问by Gill Bates
I'm reading Angular 2 "5 Min Quickstart"and there is such a line:
我正在阅读 Angular 2 "5 Min Quickstart"并且有这样一行:
import { Component } from '@angular/core';"
I can't figure out, what does @
symbol make in that import? TypeScript docs also don't say anything about that.
我不明白,@
符号在那个导入中做了什么?TypeScript 文档也没有对此进行任何说明。
What does it mean?
这是什么意思?
回答by rayray
Also of relevance is that you can use the @
symbol scoping for non-npm packages as well. You can use this in your project as a short way of referring to different directories.
同样重要的是,您也可以@
对非 npm 包使用符号范围。您可以在项目中使用它作为引用不同目录的简短方式。
i.e.
IE
import { MyService } from '@services/my.service';
import { HelloWorldComponent } from '@components/hello-world.component';
instead of
代替
import { MyService } from '../../../../my.service';
import { HelloWorldComponent } from '../shared/deeply/nested/hello-world/hello-world.component';
To do this, you simply configure your tsconfig.json file (at root of project) like this:
为此,您只需像这样配置 tsconfig.json 文件(在项目的根目录下):
{
"compileOnSave": false,
"compilerOptions": {
// omitted...
"baseUrl": "src",
"paths": {
"@services/*": ["app/path/to/services/*"],
"@components/*": ["app/somewhere/deeply/nested/*"],
"@environments/*": ["environments/*"]
}
}
}
See the full details at Angular Firebase
在Angular Firebase查看完整细节
回答by hoogw
@scope_name/package_name
@scope_name/package_name
This is NPM feature, scoped name, anything between @ and slash / will be your scope name.
这是 NPM 功能,范围名称,@ 和斜杠 / 之间的任何内容都将是您的范围名称。
回答by L.querter
this is just a naming convention that Angular uses. Since the release they renamed it to @angular/core in stead of angular2/core.
这只是 Angular 使用的命名约定。自发布以来,他们将其重命名为@angular/core 而不是 angular2/core。
It references the core components of the framework.
它引用了框架的核心组件。
(found in post - angularjs 2 with angular-material @angular/core not found)
(在后angularjs 2 中找到,angular-material @angular/core not found)