Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

node.js - Angular Mat-Form Causing Web Page to Crash Without Error Code

I am building an Angular application that has been working fine up until I added mat--form-field to build a multi-option drop down. For some reason, the web page crashes whenever the mat-form-field block is added to the code. I have tried commenting various segments of the code out and have found that the erorr appears to be the mat-form-field, however my compiler is not issuing me any errors.

selection-page.component.html

<div class=" content">
    <div class=" row">
        <div class=" col-md-12">
            <div class=" card">
              <div class=" card-body">
                <div class=" places-buttons">
                  <div class=" row">
                    <div class=" col-md-6">
                      <h2 class=" card-title">Ingest RDBMS</h2>
                    </div>
                  </div>
                  <div class=" row">
                    <div class=" col-md-12 ml-auto mr-auto text-center">
                      <div class=" row d-flex justify-content-center">
                        
                        <div class=" col-sm-1 col-2">
                            <span style="font-size: 250%;" class="text-light"><i class="fas fa-check-circle"></i></span>
                            <p style="font-size: 10px;">Source data</p>
                        </div>
                        <div class=" col-sm-1 col-1">
                            <span class="text-primary" style="font-size: 150%;"><i class="fas fa-arrow-right"></i></span>
                        </div>
                        <div class=" col-sm-1 col-3">
                            <span class="text-light" style="font-size: 250%;"><i class="fas fa-check-circle"></i></span>
                            <p style="font-size: 10px;">Configure Ingestion</p>
                        </div>
                        <div class=" col-sm-1 col-1">
                            <span class="text-primary" style="font-size: 150%;"><i class="fas fa-arrow-right"></i></span>
                        </div>
                        <div class=" col-sm-1 col-2">
                            <span  class="text-light" style="font-size: 250%;"><i class="fas fa-check-circle"></i></span>
                            <p style="font-size: 10px;">Filter Table</p>
                        </div>
                        <div class=" col-sm-1 col-1">
                            <span  class="text-primary" style="font-size: 150%;"><i class="fas fa-arrow-right"></i></span>
                        </div>
                        <div class=" col-sm-1 col-2">
                            <span  class="text-primary" style="font-size: 250%;">④</span>
                            <p style="font-size: 10px;">Queuing Table</p>
                        </div>
                        <div class=" col-sm-1 col-1">
                            <span class="text-primary" style="font-size: 150%;"><i class="fas fa-arrow-right"></i></span>
                        </div>
                        <div class=" col-sm-1 col-2">
                            <span  class="text-light" style="font-size: 250%;">⑤</span>
                            <p style="font-size: 10px;">Configuration Details</p>
                        </div>
                      </div>
                    </div>
                  </div>
                  <br>
                  <br>
                  
                </div>
              </div>
            </div>
          </div>
          <div class=" col-lg-12 ml-auto mr-auto">
            <div class=" card">
          <div class=" card-header">
          </div>
          <div class=" card-body">
            <div class="row">
              <div class="col-md-6">
                <form class="form-inline ml-auto">
                  <div class="form-group no-border">
                      <div class="input-group-prepend">
                        <div> <!--Selection Page Module-->
                            <div class="row">
                                <div class="col" id="border"> <!--Database-->
                                <div>
                                    <h4>Database Selection</h4>
                                    <mat-form-field appearance="fill">
                                    <mat-label>Database</mat-label>
                                    <mat-select [formControl]="databaseControl" multiple>
                                        <mat-option>-- None --</mat-option>
                                        <mat-optgroup *ngFor="let group of databaseGroups" [label]="group.name"
                                                    [disabled]="group.disabled">
                                        <mat-option *ngFor="let database of group.database" [value]="database.value">
                                            {{database.viewValue}}
                                        </mat-option>
                                        </mat-optgroup>
                                    </mat-select>
                                    <mat-hint></mat-hint>
                                    </mat-form-field>
                                </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col" id="border"> <!--Table-->
                                <h4>Table Selection</h4>
                            <mat-form-field appearance="fill">
                            <mat-label>Table</mat-label>
                            <mat-select [formControl]="tableControl" multiple>
                                <mat-option>-- None --</mat-option>
                                <mat-optgroup *ngFor="let group of tableGroups" [label]="group.name"
                                            [disabled]="group.disabled">
                                <mat-option *ngFor="let table of group.table" [value]="table.value">
                                    {{table.viewValue}}
                                </mat-option>
                                </mat-optgroup>
                            </mat-select>
                            </mat-form-field>
                                </div>
                                <div class="col" id="border"> <!--Column-->
                                <h4>Column Selection</h4>
                            <mat-form-field appearance="fill">
                            <mat-label>Column</mat-label>
                            <mat-select [formControl]="columnControl" multiple>
                                <mat-option>-- None --</mat-option>
                                <mat-optgroup *ngFor="let group of columnGroups" [label]="group.name"
                                            [disabled]="group.disabled">
                                <mat-option *ngFor="let column of group.column" [value]="column.value">
                                    {{column.viewValue}}
                                </mat-option>
                                </mat-optgroup>
                            </mat-select>
                            </mat-form-field>
                                </div>
                            </div>
                        </div>
                      </div>
                    </div>      
                </form>     
              </div>
            </div>
            <br><br>
          </div>
            <div class=" card-footer">
              <div class="row">
                <div class="col-md-6 col-sm-6 col-6 ">
                  <button class="btn btn-default mr-2" routerLink="/home">Cancel</button>
                  <button class="btn btn-success"><i class="fas fa-file"></i>  Save as Draft</button>
                </div>
                <div class="col-md-6 col-sm-6 col-6 d-flex justify-content-end">
                  <button class="btn btn-primary" routerLink="/ingestions/rdbms/filterTable">Previous</button>

                  <button class="btn btn-primary" routerLink="/ingestions/streamdata/configureIngestion">Next</button>
                </div>
              </div>
            </div>
      </div>
    </div>
  </div>

app.module.ts

import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { RouterModule } from "@angular/router";
import { ToastrModule } from 'ngx-toastr';

import { AppComponent } from "./app.component";
import { AdminLayoutComponent } from "./layouts/admin-layout/admin-layout.component";
import { AuthLayoutComponent } from './layouts/auth-layout/auth-layout.component';

import { NgbModule } from "@ng-bootstrap/ng-bootstrap";

import { AppRoutingModule } from "./app-routing.module";
import { ComponentsModule } from "./components/components.module";
import { DragDropModule } from '@angular/cdk/drag-drop';
import { MatCardModule } from '@angular/material/card';
import { SelectionPageComponent } from './pages/ingestions/rdbms/pages/selection-page/selection-page.component';

import {MatNativeDateModule} from '@angular/material/core';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {DemoMaterialModule} from './material-module';
import {MAT_FORM_FIELD_DEFAULT_OPTIONS} from '@angular/material/form-field';


@NgModule({
  imports: [
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    ComponentsModule,
    N

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to import the mat-select and the mat-form-field modules into your app.module.ts:

import {MatFormFieldModule} from '@angular/material/form-field';
import {MatSelectModule} from '@angular/material/select';

You also are binding to form controls ([formControl]="columnControl" and [formControl]="databaseControl"), but you have no form controls in your component.

You need to create the form controls in your selection-page.ts:

databaseControl = new FormControl();
columnControl = new FormControl();

UPDATE

I believe you also need to import the reactive forms module too:

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

I managed to replicated your page with no errors with the following app.module.ts file. I left the selection-page.ts and selection-page.html exactly as you have it.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatCardModule} from '@angular/material/card';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    CommonModule,
    MatFormFieldModule,
    MatSelectModule,
    MatCardModule
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Working screenshot

If it still doesn't work, I believe that it is not the mat-form-field elements causing your page crash and perhaps something else.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...