2
지시문에 싱글 톤 서비스를 주입하는 데 문제가 있습니다. 나는 서비스를 가지고있다 :Angular2 - 싱글 톤 서비스를 지시문에 삽입
@Injectable()
export class AuthService{ ... }
내가 부트 스트랩퍼에 넣었다.
bootstrap(AppComponent, [AuthService, ...]);
내가 지시했다, 내 구성 요소 보호 :
@Directive({
selector: '[protected]'
})
export class ProtectedDirective {
constructor(private authService:AuthService) { ... }
}
을 ... 그리고
콘솔에서@Component({
selector: 'dashboard',
directives: [ProtectedDirective],
template: '<div protected></div',
})
export class DashboardCmp { }
내가 오류를 참조 구성 요소 중 하나에 추가 :
ORIGINAL EXCEPTION: No provider for AuthService!
을
Dashbo에 제공자를 추가하는 경우 ardCmp, 다 잘 작동하지만 싱글 톤 서비스는 아닙니다. 나는 다른 구성 요소에 속성을 설정하고 지침에있을 때는 표시되지 않습니다.