回答編集履歴
1
Angularの仕様を使う処理パターンを追記
answer
CHANGED
@@ -18,4 +18,31 @@
|
|
18
18
|
}
|
19
19
|
```
|
20
20
|
|
21
|
-
あとは、`style`プロパティの改変でいけるかと。
|
21
|
+
あとは、`style`プロパティの改変でいけるかと。
|
22
|
+
|
23
|
+
もしくは、Angularでやるならば、下記のように、**フレームワークの仕様**を使っていく方が望ましいです。
|
24
|
+
|
25
|
+
```html
|
26
|
+
<!-- Angularの仕様においてのプロパティの変更 -->
|
27
|
+
<p class="sample" [style.background-color]="bgC">背景色</p>
|
28
|
+
|
29
|
+
<button (click)="change()">背景色を変更します</button>
|
30
|
+
```
|
31
|
+
|
32
|
+
```typescript
|
33
|
+
import { Component } from "@angular/core";
|
34
|
+
|
35
|
+
@Component({
|
36
|
+
selector: "my-app",
|
37
|
+
templateUrl: "./app.component.html",
|
38
|
+
styleUrls: ["./app.component.css"]
|
39
|
+
})
|
40
|
+
export class AppComponent {
|
41
|
+
// パブリック(HTMLテンプレート上でも使える)変数を定義
|
42
|
+
public bgC = "";
|
43
|
+
change() {
|
44
|
+
// 文字列を定義して、背景色を変更
|
45
|
+
this.bgC = "#FF0000";
|
46
|
+
}
|
47
|
+
}
|
48
|
+
```
|