2017-12-02 9 views
0

이제 Angular 5 응용 프로그램에서 이상한 문제가 발생합니다. 오류 스택은 다음과 같습니다.'private'키워드가 예약되어 있습니다 (35:12).이 파일 형식을 처리하기 위해 적절한 로더가 필요할 수 있습니다.

컴파일하지 못했습니다.

./src/app/registration/registration.component.ts 모듈 구문 분석 실패 : 예약 된 키워드 '개인'(35:12)이 파일 형식을 처리하기 위해 적절한 로더를해야 할 수도 있습니다. | }; | } | 생성자 (private, 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" 
    } 
} 

답변

0

때로는 작은 문제로 인해 머리가 긁힐 수 있습니다. 나는 왜 그런 작은 실수를했는지 모른다. 클래스 외부의 두 함수를 제거하면 문제가 해결됩니다. 같은 상황에서 끝난 다른 사람들과 공유하십시오.

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이을 정의되지 않은 한, 당신이 오류가 발생합니다.