angular 4 host 選擇器 sass 編譯錯誤

https://angular.io/guide/component-styles#host

使用 host 選擇器只能在 css 檔案中使用,在 sass 中會出現編譯錯誤 ,有辦法解決嗎?

ERROR in ./src/app/app.component.sass
Module build failed:
:host:hover
^
      Invalid CSS after "h": expected 1 selector or at-rule, was "host:hover: {"
      in /Users/allenguan/download/demo/src/app/app.component.sass (line 1, column 1)
Error:
:host:hover
^
      Invalid CSS after "h": expected 1 selector or at-rule, was "host:hover: {"
      in /Users/allenguan/download/demo/src/app/app.component.sass (line 1, column 1)
    at options.error (/Users/allenguan/download/demo/node_modules/node-sass/lib/index.js:291:26)
 @ ./src/app/app.component.ts 18:17-48
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

sass是沒有括號的,你改用scss應該就能編譯成功.

找到解法了
使用 @at-root :host 可以解決

3個讚