简体   繁体   English

Angular 不能在新生成的组件中使用 Scss

[英]Angular Can not use Scss in new generated component

As shown below Error Error1:如下图错误Error1:

在此处输入图像描述

[WDS] Errors while compiling. [WDS] 编译时出错。 Reload prevented.防止重新加载。
./src/app/products/products.component.sass Module build failed (from./node_modules/sass-loader/lib/loader.js): ./src/app/products/products.component.sass 模块构建失败(来自./node_modules/sass-loader/lib/loader.js):

This is my code:这是我的代码:

\\This is my new components product.components.ts
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-products',
  templateUrl: './products.component.html',
  styleUrls: ['./products.component.sass']
})
export class ProductsComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }
}

Here is error这是错误

ERROR in./src/app/products/products.component.sass Module build failed (from./node_modules/sass-loader/lib/loader.js):错误 in./src/app/products/products.component.sass 模块构建失败(来自./node_modules/sass-loader/lib/loader.js):
#DIV_1 { ^ Invalid CSS after "#DIV_1 {": expected "}", was "{" in...\src\app\products\products.component.sass (line 1, column 9) i 「wdm」: Failed to compile. #DIV_1 { ^ Invalid CSS 在 "#DIV_1 {": 预期 "}" 之后,是 "{" in...\src\app\products\products.component.sass(第 1 行,第 9 列)i 「wd编译失败。

I change from我从

styleUrls: ['./products.component.sass']

to

styleUrls: ['./products.component.css']

This can fix my problem.这可以解决我的问题。 But I don't think this is allowed answer.但我不认为这是允许的答案。 I would like to use scss.我想使用scss。 Then I might mark this for someone who face the same as me and need quick fixed.然后我可能会将此标记为与我相同并且需要快速修复的人。

You are using curly brackets in a.sass file.您在 a.sass 文件中使用大括号。

If you want to use brackets you need to use.scss extension如果要使用括号,则需要使用 .scss 扩展名

Read the difference here: Sass: Syntax在此处阅读差异: Sass:语法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM