关键字'private'被保留(35:12)您可能需要一个合适的加载程序来处理此文件类型
我在Angular 5应用程序中遇到了一个奇怪的问题。错误堆栈如下。关键字'private'被保留(35:12)您可能需要一个合适的加载程序来处理此文件类型
无法编译。
./src/app/registration/registration.component.ts模块解析失败: 关键字“私人”被保留(35:12)您可能需要适当的 加载器来处理此文件类型。 | }; | } |构造函数(私有, fb,FormBuilder); | {| this.form = fb.group({@ ./src/app/app.module.ts 16:0-78 @ ./src/main.ts @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src /main.ts
这里是我的代码。
export class RegistrationComponent implements OnInit { form;
constructor(private fb: FormBuilder) {
this.form = fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
email: ['', [Validators.required, isEmailValid('email')]],
password: ['', Validators.required],
confirmPassword: ['', Validators.required]
}, { validator: compareValidator('password', 'confirmPassword') });
}
function compareValidator(control1, control2) {
return form => {
if (form.controls[control1].value !== form.controls[control2].value) {
return { compareResult: true };
}
}
}
function isEmailValid(control) {
return control => {
var regex = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return regex.test(control.value) ? null : { invalidEmail: true };
}
}
ngOnInit() {
}
}
谁能帮我找到什么是问题?以任何机会,如果你需要看我的包版本,我附上我的package.json文件。
{ "name": "my-angular5-app",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.0.5",
"@angular/cdk": "^5.0.0-rc0",
"@angular/common": "^5.0.5",
"@angular/compiler": "^5.0.5",
"@angular/core": "^5.0.5",
"@angular/forms": "^5.0.5",
"@angular/http": "^5.0.5",
"@angular/material": "^5.0.0-rc0",
"@angular/platform-browser": "^5.0.5",
"@angular/platform-browser-dynamic": "^5.0.5",
"@angular/router": "^5.0.5",
"core-js": "^2.5.1",
"rxjs": "^5.5.3",
"zone.js": "^0.8.18"
},
"devDependencies": {
"@angular/cli": "^1.5.5",
"@angular/compiler-cli": "^5.0.5",
"@angular/language-service": "^5.0.5",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.92",
"codelyzer": "~3.2.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}
回答:
有时候一个小问题可能会让你挠头,这是一种类型。我不知道为什么我犯了这么小的错误。只是在班级之外移除这两个功能解决了问题。只需与其他可能以相同情况结束的人分享即可。
export class RegistrationComponent implements OnInit { form;
constructor(private fb: FormBuilder) {
this.form = fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
email: ['', [Validators.required, isEmailValid('email')]],
password: ['', Validators.required],
confirmPassword: ['', Validators.required]
}, { validator: compareValidator('password', 'confirmPassword') });
}
ngOnInit() {
}
}
function compareValidator(control1, control2) {
return form => {
if (form.controls[control1].value !== form.controls[control2].value) {
return { compareResult: true };
}
}
}
function isEmailValid(control) {
return control => {
var regex = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return regex.test(control.value) ? null : { invalidEmail: true };
}
}
如果删除关键字“功能”和使用定义在类中的功能,你会isEmailValid未定义得到一个错误。
以上是 关键字'private'被保留(35:12)您可能需要一个合适的加载程序来处理此文件类型 的全部内容, 来源链接: utcz.com/qa/257851.html