Meteor-Angular2 Subscription Doesnt Working Correctly

65 Views Asked by At

I have an simple app and service which i built in Meteor, Angular2. I have this register.component.ts and i have auth.service.ts. I am currently looking for: when i hit submit i want to show this response in my component.

But the problem is: i see "completed" every time. It never shows error. Here is my code;

register.component;

   export class RegisterComponent {
    constructor (private authService: AuthService) {
        this.authService.registerEvent.subscribe(
            (error) => { console.log(error); },
            () => { console.log("completed"); }
        );
    }
    onSignUpSubmit(f:NgForm, event: Event) {
        event.preventDefault();
        const email = f.value.email;
        const password = f.value.password;
        this.authService.signupUser(email, password);

    }

}

My auth.service

export class AuthService {
   registerEvent = new Subject();
    constructor (private router: Router) {

    }

    signupUser(Email: string, Password:string) {
        const registerUser =  Accounts.createUser({
                email: Email,
                password: Password
       }, (err) => {
           if (err) {
            this.registerEvent.error(err.message);
            console.log(this.registerEvent);
            }
        else {
            this.registerEvent.complete();
            }
       });
    }

}

I am new to Angular2 - TypeScript and i dont know what i am doing wrong.

0

There are 0 best solutions below