我正在研究 Angular Formio,因為我正在使用自定義 css 類,名稱CustomCSS我在 css 文件中添加了相同的名稱,如下所示這是堆棧閃電戰應用程序組件.scss.CustomCSS { margin: auto; width: 50%; border: 3px solid rgb(1, 248, 1); padding: 10px; background-color: coral; }應用程序組件.ts @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit {ngOnInit() { debugger; this.triggerRefresh = new EventEmitter(); this.http.get('http://....') .subscribe( response => { this.form = response.json();// this is my html script from DB }, err => {console.error(err)} ); }}應用程序組件.html<formio [refresh]="triggerRefresh" [form]="form" [submission]="submission" (submit)="onSubmit($event)"></formio>我的Htmlthis.form腳本如下{ "components":[ { "label":"City", "widget":"choicesjs", "customClass":"CustomCSS", "tableView":true, "data":{ "values":[ { "label":"abc", "value":"abc" ] }, "selectThreshold":0.3, "calculateServer":false, "validate":{ "required":true }, "key":"city", "type":"select", "indexeddb":{ "filter":{ } }, "input":true }, { "type":"button", "label":"Submit", "key":"submit", "disableOnInvalid":true, "input":true, "tableView":false } ], "id":4}在我的腳本中,CSS 類名也可用,但它沒有附加在視圖中。
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
使其在您的組件中工作的一種可能方法是修改該組件的樣式封裝。
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; // <-- add ViewEncapsulation?
@Component({
? selector: 'my-app',
? templateUrl: './app.component.html',
? styleUrls: [ './app.component.css' ],
? encapsulation: ViewEncapsulation.None // <-- add this line
})
話雖如此。
我仍然建議使用全局樣式并實現 css 選擇器來定位 formio 生成的 html 元素,如您的示例所示:
#app formio .control-label {
? font-weight: bold;
}
- 1 回答
- 0 關注
- 89 瀏覽
添加回答
舉報
0/150
提交
取消