2017-11-03 3 views
2

각도 튜토리얼 here을 보면 다른 모든 사람들처럼 관찰 가능을 가져 오지 않으며 authService를 가져 오지 않습니다. 여기왜 각도 튜토리얼을 Observable로 가져올 필요가 없는지

내가 TS 불평하지 얻기 위해 최소한의 무슨 짓을 :

import { AuthService } from './auth.service'; 
import { Observable } from 'rxjs/Observable'; 
import { Injectable } from '@angular/core'; 
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; 

@Injectable() 
export class AuthInterceptor implements HttpInterceptor { 
    constructor(private auth: AuthService) {} 

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { 
    // Get the auth header from the service. 
    const authHeader = this.auth.getAuthorizationHeader(); 
    // Clone the request to add the new header. 
    const authReq = req.clone({headers: req.headers.set('Authorization', authHeader)}); 
    // Pass on the cloned request instead of the original request. 
    return next.handle(authReq); 
    } 
} 

은 내가 아니에요 뭔가를하고, 아니면 그들은 단지 2 명 선으로 ​​튜토리얼을 짧게 유지하기 위해 가져 오기를 건너 뛸 않았다. 여기

+2

간결함을 위해 비 앵귤러 임포트를 생략 한 것 같습니다. 제가 언급 한 수입에 대한 필요성을 없애 버릴 것이라는 것을 알고있는 마술은 없습니다. – cartant

+0

감사합니다. 그것이 내가 추측하고 있던 것이지만, 내가 할 수있는 마술이 있기를 바랬다. –

답변

2

은 그것의 단지가 도시하지 않은 PR을 보내기하지만 을 통해 자신의 튜토리얼을 갈 경우 : Plnkr

:

https://angular.io/tutorial/toh-pt6#rxjs-imports

라이브 데모에 대한 링크가

여기서 모든 수입품을 분명히 볼 수 있습니다

파일 : app/hero-search.component.ts

import { Component, OnInit } from '@angular/core'; 
import { Router }   from '@angular/router'; 

import { Observable }  from 'rxjs/Observable'; 
import { Subject }   from 'rxjs/Subject'; 

// Observable class extensions 
import 'rxjs/add/observable/of'; 

// Observable operators 
import 'rxjs/add/operator/catch'; 
import 'rxjs/add/operator/debounceTime'; 
import 'rxjs/add/operator/distinctUntilChanged'; 
+0

@Samuel, 제 대답도 받아주십시오. –

1

내가 TS이 잘 버전입니다

불평하지 얻기 위해 최소한했던 것입니다. 각도 문서는 단순히 부정확하거나 오래된 것입니다. 그들에게 코드를 쉽게 읽을