如果你使UserService.login()返回observable(不是订阅者,就像现在一样),你可以在LoginComponent中订阅它
export class UserService { login(username: string, password: string) { return this._utils.api(request) .map(response => response.json()) ); } } export class LoginComponent implements OnInit { submitLogin() { var p = this._userService .login(this.username, this.password) .subscribe( // success (data) => { this._userService.setAccessToken(data.access_token); // redirect here... }, // error (error) => {}, // completed () => {} ) } }