3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Angular] 親コンポーネントから子コンポーネントのスタイルを変更しようとしたらハマった

Last updated at Posted at 2019-12-24

やりたかったこと

親コンポーネントで定義したスタイルを子コンポーネントへ反映させたかった。

parent-compomemt.html
<parent-compomemt>
  <child-compomemt class="double-border">
</parent-compomemt>
child-compomemt.html
<input type="text" class="input">

下記のような定義ではスタイルは反映されない。
そもそも親から子のスタイルを変えるのはお作法的にも悪いとのこと。

parent-compomemt.scss
.double-border {
  .input {
    border: double;
  }
}

解決策

:hostを使用して、子コンポーネント側で定義すれば良い。

child-compomemt.scss
:host.double-border {
  .input {
    border: double;
  }
}
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?