回答編集履歴

1

Angularの仕様を使う処理パターンを追記

2021/02/17 04:48

投稿

miyabi_pudding
miyabi_pudding

スコア9528

test CHANGED
@@ -39,3 +39,57 @@
39
39
 
40
40
 
41
41
  あとは、`style`プロパティの改変でいけるかと。
42
+
43
+
44
+
45
+ もしくは、Angularでやるならば、下記のように、**フレームワークの仕様**を使っていく方が望ましいです。
46
+
47
+
48
+
49
+ ```html
50
+
51
+ <!-- Angularの仕様においてのプロパティの変更 -->
52
+
53
+ <p class="sample" [style.background-color]="bgC">背景色</p>
54
+
55
+
56
+
57
+ <button (click)="change()">背景色を変更します</button>
58
+
59
+ ```
60
+
61
+
62
+
63
+ ```typescript
64
+
65
+ import { Component } from "@angular/core";
66
+
67
+
68
+
69
+ @Component({
70
+
71
+ selector: "my-app",
72
+
73
+ templateUrl: "./app.component.html",
74
+
75
+ styleUrls: ["./app.component.css"]
76
+
77
+ })
78
+
79
+ export class AppComponent {
80
+
81
+ // パブリック(HTMLテンプレート上でも使える)変数を定義
82
+
83
+ public bgC = "";
84
+
85
+ change() {
86
+
87
+ // 文字列を定義して、背景色を変更
88
+
89
+ this.bgC = "#FF0000";
90
+
91
+ }
92
+
93
+ }
94
+
95
+ ```