angular - 我可以用 angular/typescript 给导入的库起一个别名吗?

标签 angular typescript import alias

我遇到以下问题。我已经使用一个名为 Location 的模型工作了一段时间,但现在我发现 angular 也有这样一个模型,所以我在一个组件中遇到了以下冲突,而我同时需要这两个模型:

import { Location } from 'src/app/core/models/location.model';
import { Location }  from '@angular/common';

是否有任何解决方法,例如为库指定别名?

当前问题:

Duplicate identifier 'Location'.ts(2300)

最佳答案

您可以使用 as 关键字为导入别名以避免名称冲突。

import { Location as LocationModel } from 'src/app/core/models/location.model';
import { Location }  from '@angular/common';

关于angular - 我可以用 angular/typescript 给导入的库起一个别名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66837054/

相关文章:

python - 在 Python 中检测非点相对导入的工具?

angular - 如何在 Angular 5 中进行同步调用?

typescript - Angular2,应用程序内所有其他组件的通用覆盖组件

angular - 动态 Angular 形式清除现有值

typescript - 将多个参数传递给 rxjs 运算符

javascript - 如何从Angular7调用JavaScript的函数表达式

javascript - Angular 2在重定向后保留URL的状态

typescript 返回分配函数的推断类型,但限制返回类型以扩展预定义类型

python - 何时使用绝对导入

mysql - 复杂的定宽导入MYSQL