Angular6 未捕获错误:Can';t解析组件的所有参数:([object]?)
因此,在阅读整个错误堆栈之前,请记住,此时我无法精确指出导致问题的确切原因。但是,我将删除错误堆栈下面的代码。所以,我唯一的问题是:我在这里遇到的这个错误的来源是什么? 如果你愿意,你可以自己测试我的应用程序。它是一个简单的默认angular 6应用程序,具有从中获得的所有默认设置Angular6 未捕获错误:Can';t解析组件的所有参数:([object]?),angular6,angular-components,angular-forms,Angular6,Angular Components,Angular Forms,因此,在阅读整个错误堆栈之前,请记住,此时我无法精确指出导致问题的确切原因。但是,我将删除错误堆栈下面的代码。所以,我唯一的问题是:我在这里遇到的这个错误的来源是什么? 如果你愿意,你可以自己测试我的应用程序。它是一个简单的默认angular 6应用程序,具有从中获得的所有默认设置 ng new app-name 让我们从错误开始。应用程序像正常一样启动。当我尝试运行代码时,会弹出此错误 Uncaught Error: Can't resolve all parameters for Comp
ng new app-name
让我们从错误开始。应用程序像正常一样启动。当我尝试运行代码时,会弹出此错误
Uncaught Error: Can't resolve all parameters for Component: ([object Object]?).
at syntaxError (compiler.js:1016)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getDependenciesMetadata (compiler.js:10917)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getTypeMetadata (compiler.js:10810)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:10429)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.loadDirectiveMetadata (compiler.js:10291)
at compiler.js:23865
at Array.forEach (<anonymous>)
at compiler.js:23864
at Array.forEach (<anonymous>)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules (compiler.js:23861)
syntaxError @ compiler.js:1016
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getDependenciesMetadata @ compiler.js:10917
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getTypeMetadata @ compiler.js:10810
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata @ compiler.js:10429
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.loadDirectiveMetadata @ compiler.js:10291
(anonymous) @ compiler.js:23865
(anonymous) @ compiler.js:23864
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules @ compiler.js:23861
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents @ compiler.js:23839
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync @ compiler.js:23799
push../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync @ platform-browser-dynamic.js:143
push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule @ core.js:4352
./src/main.ts @ main.ts:11
__webpack_require__ @ bootstrap:76
0 @ main.ts:12
__webpack_require__ @ bootstrap:76
checkDeferredModules @ bootstrap:43
webpackJsonpCallback @ bootstrap:30
(anonymous) @ main.js:1
Uncaught错误:无法解析组件([object]?)的所有参数。
在syntaxError(compiler.js:1016)
在CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.\u getDependenciesMetadata(compiler.js:10917)
在CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.\u getTypeMetadata(compiler.js:10810)
在CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata(compiler.js:10429)
在CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.loadDirectiveMetadata(compiler.js:10291)
在compiler.js:23865
在Array.forEach()处
在compiler.js:23864
在Array.forEach()处
在JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules(compiler.js:23861)
syntaxError@compiler.js:1016
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.\u getDependenciesMetadata@compiler.js:10917
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.\u getTypeMetadata@compiler.js:10810
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata@compiler.js:10429
push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.loadDirectiveMetadata@compiler.js:10291
(匿名)@compiler.js:23865
(匿名)@compiler.js:23864
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules@compiler.js:23861
push../node_modules/@angular/compiler/fesm5/compiler.js.jitcomiler._compileModuleAndComponents@compiler.js:23839
push../node_modules/@angular/compiler/fesm5/compiler.js.jitcomiler.compileModuleAsync@compiler.js:23799
推送../node_modules/@angular/platform browser dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync@platform browser dynamic.js:143
push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule@core.js:4352
./src/main.ts@main.ts:11
__webpack_require__@bootstrap:76
0@main.ts:12
__webpack_require__@bootstrap:76
checkDeferredModules@bootstrap:43
webpackJsonpCallback@bootstrap:30
(匿名)@main.js:1
正如您所看到的,没有简单的方法可以判断是我的打字脚本的哪一部分导致了问题。但是,如果没有下面的代码,应用程序运行正常。所以,我的typescript组件肯定有问题
组件.ts如下所示
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild, Directive} from '@angular/core';
import { FormGroup } from '@angular/forms';
import { DefineBusinessRuleService } from '../services/define/define-business-rule.service';
import { DefineBusinessRuleNamespace } from '../model/business-rule-namespace';
@Component({
selector: 'app-define-business-rule',
templateUrl: './define-business-rule.component.html',
styleUrls: ['./define-business-rule.component.css']
})
export class DefineBusinessRuleComponent implements OnInit {
// interfaces
headers : Headers;
output: any;
@Input() minValue: string;
@Input() maxValue: string;
@Input() attribute : Array<string>;
@Input() table : Array<string>;
submitted = false;
@Input() businessRuleType : Array<string>;
ruletypes : Array<string>;
ruletype : string;
constructor(
private defineBusinessRuleService: DefineBusinessRuleService
,private model : any
) {
this.table = ['table1', 'table2', 'table3'];
this.attribute = ['attribute1', 'attribute2', 'attribute3'];
this.ruletypes = [
// atrribute
'AttributeRange',
'AttributeCompare',
'AttributeList',
'AttributeOther',
'TupleCompare',
'TupleOther'
]
model = {
minValue : 5,
maxValue : 10,
name : 'RangeRule',
description : 'This is a Range Rule',
table1 : this.table[0],
column1 : this.attribute[2],
errorMsg : 'Error message'
};
}
get diagnostic() { return JSON.stringify(this.model); }
defineNewBusinessRule() {
//this.model = new DefineBusinessRuleService(42, 50, '', '', '', '', '');
}
saveAttributeRangeRule(){
this.output = {
database_id : 1,
minValue : this.minValue,
maxValue : this.maxValue,
table1 : this.table,
column1 : this.attribute
}
this.output.stringify;
this.defineBusinessRuleService.saveAttributeRangeRule(this.output);
}
saveAttributeCompareRule(){
this.output = {
database_id : 1,
table1 : this.table,
//table2 : this.table2,
column1 : this.attribute,
//column2 : this.attribute2,
//value : this.value
}
this.output.stringify;
//this.defineBusinessRuleService.saveAttributeCompareRule(this.output);
}
ngOnInit(){
}
onSelect(){
}
onSubmit() {
this.submitted = true;
this.ruletype = this.ruletypes[0];
switch(this.ruletype){
case "AttributeRange" : {
this.saveAttributeRangeRule();
break;
};
case "AttributeCompare" : {
this.saveAttributeCompareRule();
break;
};
}
}
}
import{Component,ElementRef,EventEmitter,Input,OnInit,Output,ViewChild,Directive}来自“@angular/core”;
从'@angular/forms'导入{FormGroup};
从“../services/define/define business rule.service”导入{DefineBusinessRuleService};
从“../model/business rule namespace”导入{DefineBusinessRuleNamespace};
@组成部分({
选择器:“应用程序定义业务规则”,
templateUrl:“./define business rule.component.html”,
样式URL:['./定义业务规则.component.css']
})
导出类定义业务规则组件实现OnInit{
//接口
标题:标题;
输出:任意;
@Input()最小值:字符串;
@Input()最大值:字符串;
@Input()属性:数组;
@Input()表:数组;
提交=错误;
@Input()businessRuleType:数组;
规则类型:数组;
规则类型:字符串;
建造师(
专用定义业务规则服务:定义业务规则服务
,私人型号:任何
) {
this.table=['table1','table2','table3'];
this.attribute=['attribute1','attribute2','attribute3'];
this.ruletypes=[
//诽谤
“定语”,
“属性比较”,
“属性列表”,
“AttributeOther”,
“TupleCompare”,
“TupleOther”
]
型号={
最小值:5,
最大值:10,
名称:'RangeRule',
描述:“这是一个范围规则”,
表1:this.table[0],
column1:此.attribute[2],
errorMsg:'错误消息'
};
}
get diagnostic(){return JSON.stringify(this.model);}
定义业务规则(){
//this.model=新定义的业务规则服务(42、50、“”、“”、“”、“”);
}
saveAttributeRangeRule(){
此文件的输出={
数据库id:1,
minValue:this.minValue,
maxValue:this.maxValue,
表1:这个表,
第1列:this.attribute
}
this.output.stringify;
this.defineBusinessRuleService.saveAttributeArgerule(this.output);
}
saveAttributeCompareRule(){
此文件的输出={
数据库id:1,
表1:这个表,
//表2:这个,
第1列:this.attribute,
//第2栏:this.attribute2,
//值:这个值
}
this.output.stringify;
//this.defineBusinessRuleService.saveAttributeCompareRule(this.output);
}
恩戈尼尼特(){
}
onSelect(){
}
onSubmit(){
this.submitted=true;
this.ruletype=this.ruletypes[0];
开关(此.ruletype){
案例“定语”:{
this.saveAttributeArgerule();
打破
};
案例“属性比较”:{
这个.saveAttributeComparule();
打破
};
}
}
}
谢谢你读这篇文章!如果你像我一样以视觉为导向,那么这个表格可能会帮助你理解w
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild, Directive} from '@angular/core';
import { FormGroup } from '@angular/forms';
import { DefineBusinessRuleService } from '../services/define/define-business-rule.service';
import { DefineBusinessRuleNamespace } from '../model/business-rule-namespace';
@Component({
selector: 'app-define-business-rule',
templateUrl: './define-business-rule.component.html',
styleUrls: ['./define-business-rule.component.css']
})
export class DefineBusinessRuleComponent implements OnInit {
constructor(
private model : any
) {
model = {
minValue : 5,
maxValue : 10,
name : 'RangeRule',
description : 'This is a Range Rule',
table1 : this.table[0],
column1 : this.attribute[2],
errorMsg : 'Error message'
};
}
get diagnostic() { return JSON.stringify(this.model); }
defineNewBusinessRule() {
this.model = new DefineBusinessRuleService(42, 50, '', '', '', '', '');
}
}
}
constructor(
private model : any
) {
this.model = {
minValue : 5,
maxValue : 10,
name : 'RangeRule',
description : 'This is a Range Rule',
table1 : this.table[0],
column1 : this.attribute[2],
errorMsg : 'Error message'
};
}