j-p
j-p

Reputation: 3818

Angular 5 component expecting an argument

Im trying a simple profile app, and all the sudden Im getting error TS2554

ERROR in /app/components/profile/profile.component.ts(25,3): error TS2554: Expected 1 arguments, but got 0.

import { Component, OnInit } from '@angular/core';
import { AuthService } from '../../services/auth.service';
import { FlashMessagesService } from 'angular2-flash-messages';
import { Router } from '@angular/router';

@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {

    user: Object;

    constructor(
        private auth: AuthService,
        private flashMsg: FlashMessagesService,
        private router: Router
        ) {
    }

    ngOnInit() {

        this.auth.getProfile().subscribe( profile => {
            this.user = profile.user;
        },
        err => {
            return false;
        });

    }

}

auth.service.ts

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { tokenNotExpired } from 'angular2-jwt';

@Injectable()
export class AuthService {

    authToken: any;
    user: any;

    constructor(
        private http: Http
        ) {
    }



    getProfile(user) {
        let headers = new Headers();
        this.loadToken();
        headers.append('Authorization', this.authToken);
        headers.append('Content-Type','application/json');
        return this.http.get('http://localhost:3000/users/profile', {headers:headers})
            .map(res => res.json());
    }

    loadToken() {
        const token = localStorage.getItem('id_token');
        this.authToken = token;
    }
}

Upvotes: 1

Views: 1150

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222532

Your getProfile is expecting an argument named user but you are not passing it from the component

You need to pass an argument as follows,

  this.auth.getProfile(user).subscribe( profile => {
            this.user = profile.user;
  },
  err => {
            return false;
  });

or if you don't need an argument , remove it from your service method.

Upvotes: 1

Related Questions