1

I've been having this really annoying error. I'm working in Angular and configured the login service. Now all of a sudden it can't compile and displays a line of errors:

ERROR in src/app/login/login.component.ts(18,2): error TS1127: Invalid character. src/app/login/login.component.ts(18,3): error TS1127: Invalid character. src/app/login/login.component.ts(18,4): error TS1127: Invalid character. src/app/login/login.component.ts(18,5): error TS1127: Invalid character. src/app/login/login.component.ts(18,6): error TS1127: Invalid character. src/app/login/login.component.ts(18,7): error TS1127: Invalid character. src/app/login/login.component.ts(18,8): error TS1127: Invalid character. src/app/login/login.component.ts(18,9): error TS1127: Invalid character. src/app/login/login.component.ts(18,10): error TS1127: Invalid character. src/app/login/login.component.ts(18,11): error TS1127: Invalid character. src/app/login/login.component.ts(18,12): error TS1127: Invalid character. src/app/login/login.component.ts(18,13): error TS1127: Invalid character. src/app/login/login.component.ts(18,14): error TS1127: Invalid character.

line 18 is the last line of the following code, there are no characters on that line besides the '}'. I have absolutely no clue what I need to do next.

import { Component } from '@angular/core';
import {AuthService} from '../services/auth.service';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})

export class LoginComponent {

  constructor(public auth: AuthService) {
  }

  login() {
    this.auth.login();
  }
}         

The service file it is linked to:

import { Injectable } from '@angular/core';
import {AngularFireAuth} from "angularfire2/auth";
import * as firebase from 'firebase';
import {Observable} from "rxjs/Observable";

@Injectable()
export class AuthService {
  user$: Observable<firebase.User>;

  constructor(private afAuth: AngularFireAuth) {
    this.user$ = afAuth.authState;
  }

  login() {
    this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider());
  }

  logout(){
    this.afAuth.auth.signOut();
  }

}
Narm
  • 10,677
  • 5
  • 41
  • 54
tilly
  • 2,229
  • 9
  • 34
  • 64
  • Probably have some hidden characters in there. I note a lot of trailing spaces after your closing '}'. Try Deleting the last couple of lines and re-writing perhaps. I like to use Notepad++ with _View -> Show Symbol -> Show All Characters_ when I run into this sort of thing. – Brian Dec 01 '17 at 00:17
  • I know see that it also says 'statement expected' when I hover the '}' on the last line. I'll try the thing in Notepad you mentioned. – tilly Dec 01 '17 at 00:19
  • Ok, now for some some magic reason it got fixed. No idea how. Been trying stuff for over an hour and a half and all of a sudden it works. – tilly Dec 01 '17 at 00:21

1 Answers1

3

I got this exact same error. I got it after my IDE was acting up and crashed.

I was able to solve it by just selecting all the code in the file (Ctrl+A) and then just pasting it in right after (Ctrl+V).

That seemed to remove the hidden invalid character for me.

Mr. V
  • 46
  • 2