gpt4 book ai didi

angular - 垫卡在我的 Angular 应用程序中不起作用

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

我正在尝试在我的 Angular 应用程序中创建一个登录页面。

我的代码

<mat-card class="login">
<mat-card-content>
<div class="example-small-box mat-elevation-z4">
<form class="example-form">
<mat-form-field class="email example-full-width">
<input matInput placeholder="Email or User name" [(ngModel)]="username" name="username" required >
</mat-form-field>

<mat-form-field class="example-full-width">
<input matInput placeholder="Password" [(ngModel)]="password"type="password" name="password" required>
</mat-form-field>
</form>


<button class="btn" mat-raised-button color="primary" (click)="login()" >Login</button>
</div>

</mat-card-content>
</mat-card>

看起来像这样。 enter image description here

背景颜色是因为给定的CSS。

垫卡没有显示,空间方向也不正确。我已经导入了所有要求。

应用程序模块.ts

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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AhuComponent } from './ahu/ahu.component';
import { FlexLayoutModule } from '@angular/flex-layout';
import { LoginComponent } from './login/login.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import {MatCardModule} from '@angular/material/card';
import {MatTabsModule} from '@angular/material/tabs';
import {MatFormFieldModule} from '@angular/material/form-field';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {MatInputModule, MatButtonModule} from '@angular/material';
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

@NgModule({
declarations: [
AppComponent,
AhuComponent,
LoginComponent,
PageNotFoundComponent
],
imports: [
BrowserAnimationsModule,
BrowserModule,
AppRoutingModule,
FlexLayoutModule,
MatCardModule,
MatTabsModule,
MatFormFieldModule,
FormsModule,
MatInputModule,
MatButtonModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

我之前在另一个项目中使用过相同的代码,效果非常好。但是这次它不起作用。有人可以帮我吗

根据评论编辑,angular.json

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"BMS": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/BMS",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "BMS:build"
},
"configurations": {
"production": {
"browserTarget": "BMS:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "BMS:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "BMS:serve"
},
"configurations": {
"production": {
"devServerTarget": "BMS:serve:production"
}
}
}
}
}},
"defaultProject": "BMS"
}

最佳答案

首先,验证您的 Angular 版本是否适合 Material 版本

如果不是问题,您可能忘记了 CSS,将导入添加到您的 styles.css 文件中。

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

关于angular - 垫卡在我的 Angular 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57775560/

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