【问题标题】:Can I give an alias to an imported library in angular/typescript?我可以为 angular/typescript 中的导入库提供别名吗?
【发布时间】:2021-06-24 11:16:23
【问题描述】:

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

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

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

当前问题:

重复标识符“位置”.ts(2300)

【问题讨论】:

    标签: angular typescript import alias


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 2019-06-03
      • 2021-06-07
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      相关资源
      最近更新 更多