I am having trouble passing a parameter to a function that is defined in a service. No matter what I try, the parameter always ends up being undefined
.
login.component.ts
import { Component, OnInit } from '@angular/core';
import { AuthenticationService } from '../authentication.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
providers: [AuthenticationService]
})
export class LoginComponent implements OnInit {
credentials: {
username: '',
password: ''
};
constructor(private _authenticationService: AuthenticationService) {}
ngOnInit() { }
login() {
this._authenticationService.login(this.credentials).subscribe(
response => console.log(response),
error => console.log(error),
() => console.log('Done.')
);
}
authentication.service.ts
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
@Injectable()
export class AuthenticationService {
constructor() { }
login(credentials) {
console.log(credentials); // This is undefined
}
Can anyone help me figure out what I am missing?