Javascript 需要参数的角5分量

Javascript 需要参数的角5分量,javascript,angular,typescript,Javascript,Angular,Typescript,我正在尝试一个简单的个人资料应用程序,突然间我得到了错误TS2554 /app/components/profile/profile.component.ts(25,3)中出错:错误TS2554:应为1个参数,但得到0个 import { Component, OnInit } from '@angular/core'; import { AuthService } from '../../services/auth.service'; import { FlashMessagesService

我正在尝试一个简单的个人资料应用程序,突然间我得到了错误TS2554

/app/components/profile/profile.component.ts(25,3)中出错:错误TS2554:应为1个参数,但得到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;
    }
}

您的
getProfile
需要一个名为
user
的参数,但您没有从组件传递它

你需要通过一个论点如下

  this.auth.getProfile(user).subscribe( profile => {
            this.user = profile.user;
  },
  err => {
            return false;
  });
或者,如果不需要参数,请将其从服务方法中删除