我有一个AngularJs /角12.0.5混合应用程序,我正在移动到角适当。
在mat-form字段中使用带有matInput属性的输入时,它似乎只显示占位符/标签值,而不应用任何其他样式。例如,请参见图像:

不确定是什么导致了这一点,因为角材料模块已被正确导入,并且显示这些字段时没有控制台错误。下面是我的代码:
应用程序模块
import {BrowserModule} from '@angular/platform-browser';
import {UpgradeModule} from '@angular/upgrade/static';
import {HttpClientModule} from "@angular/common/http";
import moduleName from "./angularJS.module";
import {UIRouterUpgradeModule} from "@uirouter/angular-hybrid";
import {NgModule} from "@angular/core";
import {UserProfileModule} from "./app/modules/user/user-profile.module";
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
UpgradeModule,
UserProfileModule,
UIRouterUpgradeModule.forRoot()
]
})
export class AppModule {
constructor(private upgrade: UpgradeModule) {
console.log("Bootstrapping in Hybrid mode with Angular & AngularJS");
upgrade.bootstrap(document.body, [moduleName], {strictDi: true});
}
ngDoBootstrap() {
}
}共享模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatButtonModule } from '@angular/material/button';
import { MatTableModule } from '@angular/material/table';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { FlexLayoutModule } from '@angular/flex-layout';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule
],
exports: [
BrowserAnimationsModule,
FlexLayoutModule,
FormsModule,
MatToolbarModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatButtonModule,
MatTableModule,
MatSlideToggleModule,
ReactiveFormsModule
]
})
export class SharedModule { }用户配置文件模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UserProfileComponent } from './user-profile.component';
import { SharedModule } from "../../shared/shared.module";
@NgModule({
declarations: [
UserProfileComponent
],
imports: [
CommonModule,
SharedModule
],
exports: [
UserProfileComponent
],
entryComponents: [
UserProfileComponent
]
})
export class UserProfileModule { }用户配置文件组件
import {Component} from "@angular/core";
import {downgradeComponent} from "@angular/upgrade/static";
import angular from "angular";
@Component({
selector: "user-profile",
template: require("./user-profile.html")
})
export class UserProfileComponent {
constructor() { }
}
angular
.module('app')
.directive("userProfile", downgradeComponent({
component: UserProfileComponent
}) as angular.IDirectiveFactory);用户配置文件
<div fxFill fxLayout="column" [class.mat-elevation-z1]="true">
<mat-toolbar>
<div class="profile-header">
<h4>User Profile</h4>
</div>
</mat-toolbar>
<form fxLayout="column">
<mat-form-field>
<input matInput placeholder="First Name">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Last Name">
</mat-form-field>
<mat-form-field appearance="legacy">
<mat-label>Standard form field</mat-label>
<input matInput placeholder="Placeholder">
<mat-hint>Hint</mat-hint>
</mat-form-field>
</form>
</div>发布于 2021-06-23 15:27:45
因此,我忽略了“角”元素样式所需的默认主题。
我在根目录中添加了一个material-theme.scss文件,并将其链接到main.ts中,这立即解决了这个问题。
材料主题SCSS
// Import library functions for theme creation.
@import '~@angular/material/theming';
// Include non-theme styles for core.
@include mat-core();
// Define your application's custom theme.
$primary: mat-palette($mat-indigo);
$accent: mat-palette($mat-pink, A200, A100, A400);
$theme: mat-light-theme($primary, $accent);
// Include theme styles for Angular Material components.
@include angular-material-theme($theme);主TS
import './material-theme.scss'
发布于 2021-09-19 20:00:34
我通过执行以下操作解决了这个问题
从角包打开angular.json
projects > <your project> > architect > build > options >"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],styles
projects > <your project> > architect > test > options >下重复上述步骤
https://stackoverflow.com/questions/68101461
复制相似问题