This is because the value bound on the html has to be evaluated every time something "has changed" in the app so that if the value of the bound item has changed it will be reflected to the html, thus giving you this magical autoupdating binding. This is probably what you want in 90% of the cases, as you don't want to worry about notifying angular to update a value of a bound property.
That being said if you have some heavy logic in the getter, or you prefer to control when the value will be updated you can change the components changeDetectionStrategy to onPush like in this plunker.
@Component({
selector: 'my-app',
template: `
<div><button (click)="_service.ShowItem()">Show Item</button></div>
<div>{{_service.Item}}</div>
`,
providers: [ Service ],
changeDetection: ChangeDetectionStrategy.OnPush
})
There is an excellent explanation of how angular2 change detection works by thoughtram
This is like saying, "do not check this component when doing change detection, I will let you know when to check it".
You then can use a service called ChangeDetectorRef to mark the component for change detection.
For http what you want to do is have a trigger to do the http call and then get the value you need from the response and "cache" it somewhere so that you can bind it to the UI. The trigger can be a variety of things depending on your case, eg. interval, recursion, button etc
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…