【问题标题】:typescript angular import module [duplicate]打字稿角度导入模块[重复]
【发布时间】:2018-09-01 10:58:44
【问题描述】:

所以我正在关注角度教程here,同时我也在阅读有关模块here 的信息。现在在教程中的某个时候,作者介绍了这个导入:

import { Component, OnInit } from '@angular/core';

我在上述导入中找不到 @ 符号的任何地方。我的意思是“@angular/core”应该做什么?

【问题讨论】:

  • 只是包名。各种 Angular 包都有这个前缀;参见例如scoped packages.

标签: angular typescript syntax


【解决方案1】:

'@angular/core'@ 中表示从npm 获取东西

angular/core 只不过是folder/path

在 angular '@angular/core' 中提供了软件包列表。 当你写

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

它为您提供了一种使用 component 的方法,其中包括 template(html view), class(where logics implemented), and decorators(metadata from angular)

当你写作时

import { Component,Input } from '@angular/core';

然后您将能够使用Input properties 将数据从container component(parent) 传递到nested component(child)

当你写作时

import { Component,Output } from '@angular/core';

然后您将能够使用Output properties,它用于将数据从nested component 传递到Container component

还有更多的东西......(参考角度文档)只有从'@angular/core'导入时才有可能。

【讨论】:

  • 谢谢Sumit。现在清楚了!
  • 如果对你有帮助,请接受这个答案。
  • 我接受了。
【解决方案2】:

@ 是一个允许模块作用域的 npm 功能。这意味着core 模块是angular 命名空间的一部分。

【讨论】:

  • 感谢您的来信!
猜你喜欢
  • 2018-05-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-30
  • 2017-10-29
  • 2017-05-29
  • 2017-06-04
  • 2022-01-14
  • 2018-01-10
相关资源
最近更新 更多