为什么不能在TypeScript中导入CSS?

时间:2019-12-23 09:00:32

标签: angular typescript typescript2.0

我试图在.ts文件中导入scss样式:

import style from "./map.scss";

此文件包含:

.Map {
  z-index: 1;
  position: absolute;
}

我收到消息:

  

map.scss“'没有默认导出。

我想在Ts中使用此CSS属性,例如:

DOMFunction.createElement("div",{ id: "map", class: style.Map });

style.Map是我需要的财产

1 个答案:

答案 0 :(得分:1)

如果要导入.scss文件,则应将其包括在全局样式表中:

styles.scss:

@import url('./map.scss');

更新:

如果要在Typescript中访问SASS值(variables.scss中的$ colors),请you can read here

或者,您可以使用ngStyle自行设置样式:

<div [ngStyle]="{ 'width': 'calc(100% - ' + yourVariable + 'px)' }"></div>