2017-03-22 3 views
3

메신저 정말 2 각도에 ​​새 그리고 난 내 프로젝트에 JWT를 사용하고 싶습니다. 그래서 나는 지침을 정확히 어디서 the official page of angular2-jwt에서 기본 구성을 사용하여주고 있습니다. 인증 요청을 보내는AuthHttp에 대한 공급자가 없습니다! angular2-jwt에

import { NgModule } from '@angular/core'; 
import { Http, RequestOptions } from '@angular/http'; 
import { AuthHttp, AuthConfig } from 'angular2-jwt'; 

function authHttpServiceFactory(http: Http, options: RequestOptions) { 
    return new AuthHttp(new AuthConfig(), http, options); 
} 

@NgModule({ 
    providers: [ 
    { 
     provide: AuthHttp, 
     useFactory: authHttpServiceFactory, 
     deps: [Http, RequestOptions] 
    } 
    ] 
}) 
export class AuthModule {} 

다음 단계 : 나는 다음과 같은 코드로 auth.module.ts라는 파일을 만듭니다.

import {Component, OnInit,trigger,state,style,transition,animate,keyframes, group} from '@angular/core'; 
import initDemo = require('../../../assets/js/charts.js'); 
import initNotify = require('../../../assets/js/notify.js'); 
import { AuthHttp } from 'angular2-jwt'; 

declare var $:any; 

@Component({ 
    moduleId: module.id, 
    selector: 'calendario', 
    templateUrl: 'calendario.component.html' 

}) 

export class CalendarioComponent{ 
    thing: any; 
    constructor(public authHttp: AuthHttp) {} 
    obtenerDatos() { 
     this.authHttp.get('http://localhost/autorepuestos/web/app_dev.php/api/conjunto') 
     .subscribe(
     data => this.thing = data, 
     err => console.log(err), 
     () => console.log('Request Complete') 
    ); 
     console.log("Hola"); 
    } 
} 

내가이 구성 요소에 입력 할 때이 오류가 calendario.components.ts :

파일 : 나는 내가 페이지에 제시 한 코드를 실행하는 함수를 호출하는 버튼을 넣어 구성 요소를 사용하여 :

EXCEPTION: Uncaught (in promise): Error: No provider for AuthHttp! 
Error: DI Error 

어떤 문제 해결 방법이 있습니까? 나는 앵글 2에서 정말 새로운 도움을 주셔서 감사합니다!

답변

5

AuthHttp 클래스를 제공 할 모듈을 만들었습니다. AuthModuleCalendarioComponent에 속하는 모듈 가져 오기에 있는지 확인 했습니까? 이 같은

뭔가 :

import { AuthModule } from '...'; 
import { CalendarioComponent } from '...'; 

@NgModule({ 
    imports: [AuthModule], 
    declarations: [CalendarioComponent] 
}) 
export class SomeModule {} 
+0

안녕 내 친구, 도움이 나에게 고마워요. 우 ... 알 겠어! 아마 나는 이것에 아주 newbe 다! 그래서, calendario.module.ts라는 파일이 필요합니까? 나는이 파일이 없다! –

+0

나는 약간 혼란 스럽다. 내 calendario 구성 요소를 가져올 수 없습니다. 난 그냥 내 사이드 ​​바의 routerlink에서 그를 호출 ... –

+0

Nevermind 내가 찾았 어 ... 내가 코드를 테스트하자 –