angular2-changedetection

change detection in angular2 using shared service

老子叫甜甜 提交于 2019-12-23 02:04:22
问题 i am having a parent function ngOnInit() which gets the value from google maps as follow instance.input = document.getElementById('google_places_ac'); autocomplete = new google.maps.places.Autocomplete(instance.input, { types: ['(cities)']}); google.maps.event.addListener(autocomplete, 'place_changed', function () { var place = autocomplete.getPlace(); instance.setValue(place.address_components[3].long_name, place.address_components[2].long_name, place.address_components[1].long_name); });

Angular: Change in Pipe not detected

我与影子孤独终老i 提交于 2019-12-22 04:37:46
问题 I have this pipe which multiplies the input value by an other value retrieved from a service: @Pipe({ name: 'multiply' }) export class MultiplyPipe implements PipeTransform { constructor(private service: StateService) { } transform(value: any, args?: any): any { return value * this.service.multiplier; } } Usage: {{ value | multiply }} DEMO This works fine, but when the multiply value from the service is changed, it doesn't trigger any change detection, and thus {{ value | multiply }} is not

angular2 change detection on resize div

落爺英雄遲暮 提交于 2019-12-22 03:02:01
问题 I use bootstrap for my layout and I need to check if the automatic calculated size of my DIV with bootstrap for example width = 25% is changed. Is there a possibility to do change detection on a attribute which I don't set in my template, but is set by bootstrap. (window:resize) is not enough. thx 回答1: You can add a directive to the div and implement lifecycle hook ngDoCheck() to perform your own change detection logic. You'll need to inject ElementRef : constructor(private _elRef:ElementRef)

angular2 change detection on resize div

六月ゝ 毕业季﹏ 提交于 2019-12-22 03:01:10
问题 I use bootstrap for my layout and I need to check if the automatic calculated size of my DIV with bootstrap for example width = 25% is changed. Is there a possibility to do change detection on a attribute which I don't set in my template, but is set by bootstrap. (window:resize) is not enough. thx 回答1: You can add a directive to the div and implement lifecycle hook ngDoCheck() to perform your own change detection logic. You'll need to inject ElementRef : constructor(private _elRef:ElementRef)

Why do I need to call detectChanges() with the default change detection strategy?

烈酒焚心 提交于 2019-12-21 11:10:10
问题 I am working on an Angular 4 app, but I am having a problem inasmuch as I am having to call this.changeDetectorRef.detectChanges(); to update the view when the model changes. For example, I have this code which is for pagination: changePage(pageNumber) { this.currentPage = pageNumber; // why do I need to do this? this.changeDetectorRef.detectChanges(); } I have expicitly set the change detection strategy on the component to ChangeDetectionStrategy.Default but this has no effect. It is

Why do I need to call detectChanges() with the default change detection strategy?

和自甴很熟 提交于 2019-12-21 11:09:11
问题 I am working on an Angular 4 app, but I am having a problem inasmuch as I am having to call this.changeDetectorRef.detectChanges(); to update the view when the model changes. For example, I have this code which is for pagination: changePage(pageNumber) { this.currentPage = pageNumber; // why do I need to do this? this.changeDetectorRef.detectChanges(); } I have expicitly set the change detection strategy on the component to ChangeDetectionStrategy.Default but this has no effect. It is

How to re-trigger all pure pipes on all component tree in Angular 2

大憨熊 提交于 2019-12-21 03:24:28
问题 I have pure pipe TranslatePipe that translates phrases using LocaleService that has locale$: Observable<string> current locale. I also have ChangeDetectionStrategy.OnPush enabled for all my components including AppComponent . Now, how can I reload whole application when someone changes language? (emits new value in locale$ observable). Currently, I'm using location.reload() after user switches between languages. And that's annoying, because whole page is reloaded. How can I do this angular

How to detect change from one component into other

喜你入骨 提交于 2019-12-21 01:27:08
问题 Angular 4. Github source I have a menu which is filled by a web service. The web service is in taskService, but is not necessary now. ngOnInit() { this.getTasks(); } getTasks(): void { this.taskService.getTasks() .subscribe(Tasks => this.tasks = Tasks); } When you click on a task it loads a page, a different component, with a form ready to update the data. It is also made by a web service and works fine. The problem is that after update the task, it is not reflected in the task menu I am

Increase performance on Angular2 inputfield

丶灬走出姿态 提交于 2019-12-19 04:22:51
问题 I have a list of components that contain dates(formatted with toLocaleString() ) and other things. On top of them there is a component for creating new components, wich contains a form with some inputfields built with angulars FormBuilder. When I type fast the validation lags and the text I'm typing isn't displayed immediately. I assume that Angular is rerendering all components, because if I don't display the date in the other components I can type pretty fast without lags. Is there a way to

Increase performance on Angular2 inputfield

妖精的绣舞 提交于 2019-12-19 04:21:52
问题 I have a list of components that contain dates(formatted with toLocaleString() ) and other things. On top of them there is a component for creating new components, wich contains a form with some inputfields built with angulars FormBuilder. When I type fast the validation lags and the text I'm typing isn't displayed immediately. I assume that Angular is rerendering all components, because if I don't display the date in the other components I can type pretty fast without lags. Is there a way to