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 –
第二個作品謝謝 –