首页 文章

角度材料步进器无法工作 - Angular 6

提问于
浏览
0

Angular材料Stepper不起作用Angular-6,我按照它们提供的说明但是我遇到了一些冲突,任何人都知道如何解决这个问题会出现很多错误

谢谢

获取http://gc.kis.v2.scr.kaspersky-labs.com/46C70D82-2833-B24C-9A8E-E03849F5DBD7/main.js net :: ERR_ABORTED 404 localhost /:1拒绝从'http:来应用样式: //localhost:4200/node_modules/ngx-bar-rating/themes/br-default-theme.css'因为其MIME类型('text / html')不是受支持的样式表MIME类型,并且启用了严格的MIME检查 . compiler.js:2547未捕获错误:模板解析错误:无法绑定到'formGroup',因为它不是'form'的已知属性 . (“-stepper labelPosition =”bottom“stepper>] [formGroup] =”firstFormGroup“>填写你的名字”):ng:///AppModule/BookingcalendarComponent.html@4:12无法绑定到'formGroup'它不是“形式”的已知属性 . (“] [formGroup] =”secondFormGroup“>在TemplateParser.push ../ node_modules /的syntaxError(compiler.js:2547)处填写您的地址”):ng:///AppModule/BookingcalendarComponent.html@15:12 JitCompiler.push上的@ angular / compiler / fesm5 / compiler.js.TemplateParser.parse(compiler.js:19495)../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate(compiler.js:25041 )在JitCompiler.push上的Set.forEach()的JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate(compiler.js:25028)at compiler.js:24971编译器上的node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents(compiler.js:24971):在JitCompiler.push上的Object.then(compiler.js:2538)编译24881 .. / node_modules / @ angular / compiler / fesm5 / compiler.js.JitCompiler._compileModuleAndComponents(compiler.js:24880)

My code part, html

<mat-horizontal-stepper labelPosition="bottom" #stepper>
        <mat-step [stepControl]="firstFormGroup">
          <form [formGroup]="firstFormGroup">
            <ng-template matStepLabel>Fill out your name</ng-template>
            <mat-form-field>
              <input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
            </mat-form-field>
            <div>
              <button mat-button matStepperNext>Next</button>
            </div>
          </form>
        </mat-step>
        <mat-step [stepControl]="secondFormGroup" optional>
          <form [formGroup]="secondFormGroup">
            <ng-template matStepLabel>Fill out your address</ng-template>
            <mat-form-field>
              <input matInput placeholder="Address" formControlName="secondCtrl" required>
            </mat-form-field>
            <div>
              <button mat-button matStepperPrevious>Back</button>
              <button mat-button matStepperNext>Next</button>
            </div>
          </form>
        </mat-step>
        <mat-step>
          <ng-template matStepLabel>Done</ng-template>
          You are now done.
          <div>
            <button mat-button matStepperPrevious>Back</button>
            <button mat-button (click)="stepper.reset()">Reset</button>
          </div>
        </mat-step>
      </mat-horizontal-stepper>

.ts

import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({
  selector: 'app-Bookingcalendar',
  templateUrl: './Bookingcalendar.component.html',
  styleUrls: ['./Bookingcalendar.component.css']
})
export class BookingcalendarComponent implements OnInit {
  firstFormGroup: FormGroup;
  secondFormGroup: FormGroup;
  constructor(private _formBuilder: FormBuilder) { }

  ngOnInit() {
    this.firstFormGroup = this._formBuilder.group({
      firstCtrl: ['', Validators.required]
    });
    this.secondFormGroup = this._formBuilder.group({
      secondCtrl: ['', Validators.required]
    });
  }
}

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>ProjectOne</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
  <link rel="stylesheet" href="assets/css/style.css">
  <link rel="stylesheet" href="assets/css/carousel.css">

  <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css">
  <link rel="stylesheet" href="../node_modules/ngx-bar-rating/themes/br-default-theme.css">
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>



</head>
<body>
  <app-root></app-root>
</body>
</html>

1 回答

  • 0

    您需要在声明 BookingcalendarComponent 的模块中导入 ReactiveFormsModule ,例如

    import { ReactiveFormsModule } from '@angular/forms';
    
    @NgModule({
      imports: [
        // other imports ...
        ReactiveFormsModule
      ],
    })
    export class AppModule { }
    

    https://angular.io/guide/reactive-forms

相关问题