angular - 在 Angular 中使用 mat-form-field 时启动画面挂起
问题描述
我正在创建一个使用闪屏的应用程序。一切正常,直到我将 mat-form-field 元素添加到登录页面。然后启动屏幕显示并且永远不会消失。
这是一个错误还是其他什么?我该如何规避这个?
您可以在下面找到代码。
我的启动画面实现:
闪屏组件.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'splash-screen',
templateUrl: './splash-screen.component.html',
styleUrls: ['./splash-screen.component.css'],
})
export class SplashScreenComponent implements OnInit {
windowWidth: string;
//showSplash = true;
showSplash = false;
ngOnInit(): void {
setTimeout(() => {
this.windowWidth = '-' + window.innerWidth + 'px';
setTimeout(() => {
this.showSplash = !this.showSplash;
}, 500);
}, 3000);
}
}
闪屏.component.html
<div
class="app-splash-screen"
[ngStyle]="{ left: windowWidth }"
*ngIf="showSplash"
>
<div class="app-splash-inner">
<div class="app-logo"></div>
<div class="app-label">LINK easy</div>
<div class="app-loader"></div>
</div>
</div>
我的登陆页面的实现。这是问题所在:mat-form-field。当我删除表单内的所有内容时,启动屏幕会起作用。
登陆页面.component.html
<div class="main-container">
<div class="flex-container">
<!-- <h1 class="header">Mitä tarvitset?</h1> -->
<mat-card>
<button
mat-button
class="button buttonContent"
mat-button
routerLink="/projects"
>
<span class="buttonText">PROJEKTIT</span>
</button>
<button
mat-button
class="button buttonContent"
mat-button
routerLink="/experts"
>
<span class="buttonText">ASIANTUNTIJAT</span>
</button>
<button
mat-button
class="button buttonContent"
mat-button
routerLink="/landing"
>
<span class="buttonText">TARJOUSPYYNTÖ</span>
</button>
<button
mat-button
class="button buttonContent"
mat-button
routerLink="/contact"
>
<span class="buttonText">YHTEYDENOTTO</span>
</button>
<button
mat-button
class="button buttonContent"
mat-button
routerLink="/landing"
>
<span class="buttonText">REFERENSSIT</span>
</button>
<form class="tp-form">
<mat-form-field class="tp-full-width">
<input
type="text"
placeholder="Hae tästä"
aria-label="Number"
matInput
[formControl]="myControl"
[matAutocomplete]="auto"
/>
<mat-autocomplete #auto="matAutocomplete">
<mat-option
[routerLink]="['/expert-details']"
[state]="{ id: name[0], name: name }"
*ngFor="let name of names"
[value]="name[0]"
>
{{ name[1] }}
</mat-option>
<mat-option
[routerLink]="['/expert-details']"
[state]="{ id: name[0], name: name }"
*ngFor="let name of names"
[value]="name[0]"
>
{{ name[2] }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</mat-card>
</div>
</div>
登陆页面.component.ts
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MatAutocomplete } from '@angular/material/autocomplete';
@Component({
selector: 'app-landing-page',
templateUrl: './landing-page.component.html',
styleUrls: ['./landing-page.component.css'],
})
export class LandingPageComponent implements OnInit {
title = 'materialApp';
myControl = new FormControl();
niilo = 'Niilo Salminen';
elli = 'Elli Saartamo';
mari = 'Mari Paananen';
UXDesigner = 'UX Designer';
RDEngineer = 'R&D Engineer';
industrialDesigner = 'Industrial Designer';
names = [
[0, this.niilo, this.UXDesigner],
[1, this.elli, this.RDEngineer],
[2, this.mari, this.industrialDesigner],
];
constructor() {}
ngOnInit(): void {}
}
解决方案
解决了。我试图将 undefined 分配给 [value]。
推荐阅读
- javascript - 比较两个数组并将对象添加到另一个数组
- linux - `entry_SYSCALL64_slow_path` 和 `entry_SYSCALL64_fast_path` 的区别
- neo4j - 密码查询 Neo4J
- python - X.func 和 X.func( ) 的区别
- json - Firestore 将架构结构导出到 json
- java - Java Kafka Stream - Avro 序列化程序错误
- c - c中的字符输入
- android - 使用 Google 的 FIT API 跟踪当天的总步数
- mysql - 即使用户拥有所有权限,如何在春季启动中解决“用户'user'@'localhost'的java.sql.sqlexception访问被拒绝”?
- server - 创建 Minecraft 服务器时,我必须使用 ISP 提供的 Suddenlink 调制解调器/路由器,还是可以使用第二个 Nighthawk 路由器?