我正在使用ANGLE创建一个基本的Web应用程序.我想创建3列Scrum板.

在第一篇专栏文章中,我想创建一个按钮,只要您单击它,就会打开一个模式对话框.问题是,一旦将模式对话框实现到按钮中,按钮就变得不可见,甚至页脚也消失了.

以下是所有内容:

body.component.html:

<div class="board-container">
    <div class="column" id="offen">
        <app-task-form></app-task-form>
    </div>
    <div class="column" id="bearbeitung">
        <!-- Hier kommen Aufgaben in der Kategorie "In Bearbeitung" -->
    </div>
    <div class="column" id="abgeschlossen">
        <!-- Hier kommen Aufgaben in der Kategorie "Abgeschlossen" -->
    </div>

task-form.component.html:

<input type="text" [(ngModel)]="taskTitle" placeholder="Enter task title" />
<button mat-raised-button (click)="openModal()">Open Modal</button>

task-form.component.ts:

import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';

import { ModalComponent } from '../modal/modal.component';

@Component({
  selector: 'app-task-form',
  templateUrl: './task-form.component.html',
  styleUrls: ['./task-form.component.css']
})
export class TaskFormComponent {
  taskTitle: string = ''; // Eine Eigenschaft, um den Aufgabentitel zu speichern

  constructor(public dialog: MatDialog) {}

  openModal() {
    this.dialog.open(ModalComponent);
  }
}

modal.component.ts:

import { Component } from '@angular/core';

@Component({
  selector: 'app-modal',
  templateUrl: './modal.component.html',
  styleUrls: ['./modal.component.css']
})
export class ModalComponent {

}

app.module.ts:

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


import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { BodyComponent } from './body/body.component';
import { FooterComponent } from './footer/footer.component';
import { TaskFormComponent } from './task-form/task-form.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ModalComponent } from './modal/modal.component';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    BodyComponent,
    FooterComponent,
    TaskFormComponent,
    ModalComponent
    ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule, // Füge FormsModule hinzu
    BrowserAnimationsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

推荐答案

当您查看浏览器开发工具时,控制台显示: "Error NullInjectorError:R3InjectorError(AppModule)[MatDialog->;MatDialog]: NullInjectorError:没有MatDialog的提供程序!"

该错误意味着您的应用程序中没有包含material 对话框模块,因此没有提供程序.

在app.mode.ts中,您必须将MatDialogModule添加到导入中.

App.mode.ts:

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


import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { BodyComponent } from './body/body.component';
import { FooterComponent } from './footer/footer.component';
import { TaskFormComponent } from './task-form/task-form.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ModalComponent } from './modal/modal.component';
import { MatDialogModule } from '@angular/material/dialog';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    BodyComponent,
    FooterComponent,
    TaskFormComponent,
    ModalComponent
    ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule, // Füge FormsModule hinzu
    BrowserAnimationsModule,
    MatDialogModule

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Javascript相关问答推荐

使用useup时,React-Redux无法找到Redux上下文值

如何在表格上拥有水平滚动条,在正文页面上拥有垂直滚动条,同时还对html表格的标题使用位置粘性?

Klaro与Angular的集成

如何最好地从TypScript中的enum获取值

嵌套异步JavaScript(微任务和macrotask队列)

如何从html元素创建树 struct ?

在286之后恢复轮询

如何从Intl.DateTimeFormat中仅获取时区名称?

从页面到应用程序(NextJS):REST.STATUS不是一个函数

在使用位板时,如何在Java脚本中判断Connect 4板中中柱的对称性?

将Node.js包发布到GitHub包-错误ENEEDAUTH

无法避免UV:flat的插值:非法使用保留字"

按什么顺序接收`storage`事件?

在Odoo中如何以编程方式在POS中添加产品

在不扭曲纹理的情况下在顶点着色器中旋转UV

将相关数据组合到两个不同的数组中

如何在每隔2分钟刷新OKTA令牌后停止页面刷新

调用特定数组索引时,为什么类型脚本不判断未定义

是否有静态版本的`instanceof`?

与find()方法一起使用时,Mongoose中的$or运算符没有提供所有必需的数据