2016-11-30 2 views
2

나는 서비스 2로 서비스 1에서 서비스 2데이터 2와 서비스를 전달하는 방법이 각도 2에 있습니까?

나는 서비스 1을 발견하는 유일한 방법은 윈도우를 사용하는 서비스 2와 통신

[ 'var에 비슷한

서비스 1

@Injectable() 
export class Service1 { 
    ... 
} 

데이터를 전달해야 '] (Service1에 설정, Service2로 읽음)

이 방법은 실제 솔루션보다 "해킹"되지만 제 3의 서비스를 주입하는 것은 효과가 없다고 생각합니다.

다른 솔루션은 localstorage을 사용하고 있지만 나에게 이상적인 것은 아닙니다.

단서가 있습니까?

답변

1

당신은 단지 하나 개의 서비스가 다른 서비스의 변화에 ​​가입 할 수 있도록도 DI with cyclic dependency with custom HTTP and ConfigService

또한 관찰 가능한을 사용할 수있는 또 다른

@Injectable() 
class Service2 { 
    // constructor(private service2:Service2) {} 
    // cyclic dependencies are not supported 
    // therefore only one service can inject the other, 
    // but both directions at the same time causes an exception 

    someProp:String = 'xxx'; 
} 

@Injectable() 
class Service1 { 
    constructor(private service2:Service2) { 
    console.log(service2.someProp); 
    } 
} 

페이지에 하나 개의 서비스를 주입 할 수 있습니다.

관련 문제