0
调用组件:角2 - 创建万达部件用相同的服务实例
<some-component></some-component>
<some-component></some-component>
组件:
@Component ({
selector : 'some-component',
})
export class SomeComponent implements OnInit {
constructor (private someService : SomeService) {}
ngOnInit(): void {
this.someService.register();
}
}
服务:
@Injectable()
export class SomeService{
private targets: Array;
constructor (private http: Http) {}
register(){
this.targets.push('x');
getData();
}
getData(){
console.log(targets);
let params = this.targets.join(); // 'x,x'
return this.http.get(params);
}
}
控制台:
['x']
['x','x']
// what I need to do to whit until the last one and make the get request.
你好,你可以在我的代码中看到我需要调用组件多次使用相同的注射服务,而不是重复GET请求只是让GET请求一次所有组件
但我想寄存器阵列中推动价值在每一个组件,这个标志只是推动首先调用@Dummy –
这有什么另一种方式来解决,如果没有标志它的分量输入? ? 这真的是个好主意,但我需要解决这个问题,而不会在组件中标记它@Dummy –
第二个作品谢谢 –