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” 已知的“形式”属性。 (“ -stepper labelPosition =“ bottom” 步进> ] [formGroup] =“ firstFormGroup”> 填写你的名字 “):ng:///AppModule/BookingcalendarComponent.html@4:12无法绑定到“ formGroup”,因为它不是“ form”的已知属性。( ] [formGroup] =“ secondFormGroup”> 填写您的地址“):ng:///AppModule/BookingcalendarComponent.html@15:12 在语法错误(compiler.js:2547) 在TemplateParser.push ../ node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:19495) 在JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate中 (compiler.js:25041) 在JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate中 (compiler.js:25028) 在compile.js:24971 在Set.forEach() 在JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:24971) 在compile.js:24881 在Object.then(compiler.js:2538) 在JitCompiler.push ../ node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:24880)
我的代码部分 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>
答案 0 :(得分:1)
例如,您需要在声明ReactiveFormsModule
的模块中导入BookingcalendarComponent
,例如
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
// other imports ...
ReactiveFormsModule
],
})
export class AppModule { }