gpt4 book ai didi

Angular Elements 没有正确包含 Material Theme css

转载 作者:行者123 更新时间:2023-12-05 05:08:56 25 4
gpt4 key购买 nike

我在我的 Angular 元素项目中包含了 Angular Material 。我已经按照文档的建议包含了所有引用资料,但是当我构建时看起来像是 Angular ,根本不包含 Material 主题。

这是观看我的意思的链接:https://next.plnkr.co/edit/3JIbOfnyKiefS31N?open=lib%2Fscript.js

包裹所有组件的 Material 模块

import {NgModule} from '@angular/core';
import {MatIconModule} from '@angular/material/icon';
import {MatInputModule} from '@angular/material/input';
import {MatSelectModule} from '@angular/material/select';
import {MatFormFieldModule} from '@angular/material';

@NgModule({
exports: [
MatSelectModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
]
})
export class MaterialModule {}

应用模块

import { BrowserModule } from '@angular/platform-browser';
import {Injector, NgModule} from '@angular/core';

import {GalleryComponent} from './gallery/gallery.component';
import {createCustomElement} from '@angular/elements';

import {ImageService} from './gallery/image.service';
import { ImageComponent } from './gallery/image/image.component';
import { ImageDetailsComponent } from './gallery/image-details/image-details.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MaterialModule} from './material.module';

@NgModule({
declarations: [
GalleryComponent,
ImageComponent,
ImageDetailsComponent
],
imports: [
MaterialModule,
BrowserAnimationsModule,
BrowserModule
],
entryComponents: [GalleryComponent],
providers: [ImageService],
})
export class AppModule {
constructor(private injector: Injector) {}

ngDoBootstrap() {
const custom = createCustomElement(GalleryComponent, { injector: this.injector });
customElements.define('slim-gallery', custom);
}
}

风格

@import "~@angular/material/prebuilt-themes/deeppurple-amber.css";

body {
font-family: Roboto, Arial, sans-serif;
margin: 0;
}

.basic-container {
padding: 30px;
}

.version-info {
font-size: 8pt;
float: right;
}

组件模板html

<mat-form-field>
<mat-label>Favorite food</mat-label>
<mat-select>
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>

最佳答案

我遇到了同样的问题。尝试在您的 app.component.css 上添加这一行(这是用于 indigo 主题)

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

然后在你的组件上使用 encapsulation none,如下所示:

@Component({
...,
encapsulation: ViewEncapsulation.None
})

关于Angular Elements 没有正确包含 Material Theme css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57960983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com