Javascript 未捕获错误:Can';t解析AppComponent的所有参数:(?)
在构造函数中添加formbuilder时。我一直在犯错误。我已经在app.module中添加了ReactiveFormsModuleJavascript 未捕获错误:Can';t解析AppComponent的所有参数:(?),javascript,angular,angular-reactive-forms,angular-forms,Javascript,Angular,Angular Reactive Forms,Angular Forms,在构造函数中添加formbuilder时。我一直在犯错误。我已经在app.module中添加了ReactiveFormsModule import { Component } from '@angular/core'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; @Component({ selector: 'app', template: require('.
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
@Component({
selector: 'app',
template: require('./app.component.pug'),
styles: [require('./app.component.scss')]
})
export class AppComponent {
private loginForm: FormGroup;
constructor(private fb: FormBuilder) {}
}
示例app.module.ts
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [BrowserModule, ReactiveFormsModule],
declarations: [AppComponent],
providers: [],
bootstrap: [AppComponent]
})
以下是错误:
这对我来说非常有用
不过有一些评论:
- 为什么需要pug文件作为模板?如果您使用的是帕格(和帕格手表),html文件也应该在那里李>
- 为什么需要css?只需简单地使用
样式URL:['./app.component.css']
- 您确定您的节点、npm和angular版本是最新的且兼容吗李>
@Component({
selector: 'app',
template: './app.component.html',
styles: ['./app.component.scss']
})
angular中还没有原生的pug支持,所以您应该依赖其他工具将页面转换为html文件。在@Component decorator中,您应该尝试遵守官方文档。
就我个人而言,我使用它来同时启动我的开发应用程序和一个哈巴狗观察者。
这是我的gulpfile:
const gulp = require('gulp');
const clean = require('gulp-clean');
const pug = require('gulp-pug');
const git = require('gulp-git');
const file = require('gulp-file');
const spawn = require('child_process').spawn;
const shell = require('gulp-shell');
const install = require('gulp-install');
const notify = require('gulp-notify');
// *********
// BUILD APP
// *********
gulp.task('npm-install', function () {
gulp.src(['./package.json'])
.pipe(install());
});
gulp.task('clean-dist', ['npm-install'], function () {
return gulp.src('./dist', {read: false})
.pipe(clean())
});
gulp.task('pug-build', function buildHTML() {
return gulp.src('./src/**/*.pug')
.pipe(pug({doctype: 'html', pretty: false}))
.on('error', notify.onError(function (error) {
return 'An error occurred while compiling pug.\nLook in the console for details.\n' + error;
}))
.pipe(gulp.dest('./src'))
});
gulp.task('ng-build', ['clean-dist', 'pug-build'], function (cb) {
spawn('npm', ['run', 'ngbuild'], {stdio: 'inherit'})
});
gulp.task('build', ['ng-build'], function () {
});
// ****************
// DEVELOPMENT MODE
// ****************
gulp.task('pug-watch', ['pug-build'], function (cb) {
gulp.watch('./src/**/*.pug', ['pug-build'])
});
gulp.task('ng-serve', function (cb) {
spawn('ng', ['serve'], {stdio: 'inherit'});
});
gulp.task('dev-start', ['pug-watch', 'ng-serve']);
(在package.json中,我有一个条目:
“ngbuild”:“ng build--aot--progress=false”
)向tsconfig.json文件添加了emitdecoratormatadata:true
您是否尝试导入FormsModule?尝试从模板和样式标记中删除require关于删除构造函数(私有fb:FormBuilder){}
并将FormBuilder
放入另一个方法?模板和样式标签不是问题所在。我一直在使用require,因为我的模板是一个pug,我的样式是一个scss文件。如果不使用它,为什么要导入FormsModule?我一直在使用angular fullstack generator。我不知道这是否是他们的问题,你只能在示例项目中看到FormsModule,因为他们默认导入它。是AngularJS工具吗?它是一个生成器,用于为angular、node和MongoDB创建文件和文件夹。如果您删除require
部分,它是否可以无错误地构建?