angular2-changedetection

Angular2 ChangeDetection or Observable?

点点圈 提交于 2019-12-19 03:24:18
问题 I'm having difficulty with a component that doesn't refresh upon log in. The component is navbar.component that contains links to my pages/components. On it, there is a "login" link that renders login.component on which I can provide username and password and click the login button. login.component uses user.service which calls the backend with the username and password provided by login.component, stores the received token and redirects to '/'. At this point, the "login" link on navbar

“async” pipe not rendering the stream updates

一世执手 提交于 2019-12-18 03:17:08
问题 Trying to render the window size on window resize through a stream in an angular 2 component utilizing an async pipe: <h2>Size: {{size$ | async | json}}</h2> const windowSize$ = new BehaviorSubject(getWindowSize()); Observable.fromEvent(window, 'resize') .map(getWindowSize) .subscribe(windowSize$); function getWindowSize() { return { height: window.innerHeight, width: window.innerWidth }; } @Component({ selector: 'my-app', providers: [], template: ` <div> <h2>Size: {{size$ | async | json}}<

Prevent a native browser event ( like scroll ) from firing change detection

痴心易碎 提交于 2019-12-17 23:25:17
问题 I'm binding an scroll event to capture the scroll and do something with it, I've created a directive like bellow : So I have simple directive which has nothing but : constructor ( private el : ElementRef , private renderer : Renderer ) { this.domAdapter = new browser.BrowserDomAdapter(); this.ruler = new Ruler( this.domAdapter ); } ngAfterViewInit () : any { this.renderer.listenGlobal( 'window' , 'scroll' , ()=> { console.log( 'scrolling' ); } ); return undefined; } This is working fine ,

Angular 2 Component listen to change in service

淺唱寂寞╮ 提交于 2019-12-17 23:17:16
问题 I've a simple question about change detection. I have a component and a (global) service with a boolean inside. How can I make the component listen to that boolean and execute a function if that boolean changes? Thanks! 回答1: Depending on how that boolean changes you could expose it as an Observable<boolean> on your service, and then subscribe to that stream in your component. Your service would look something like: @Injectable() export class MyBooleanService { myBool$: Observable<boolean>;

How to trigger change detection in Angular2? [duplicate]

谁说我不能喝 提交于 2019-12-17 22:42:02
问题 This question already has answers here : Triggering change detection manually in Angular (5 answers) Closed 3 years ago . I'm creating a Facebook service that calls the Facebook javascript api and am wondering how to best implement change detection when my values are updated. I have a UserService which has a currentUser property that is a BehaviorSubject: currentUser: Subject<User> = new BehaviorSubject<User>(new User(null)); And when I want to update the user in response to the facebook

Angular change detection process repainting the dom

眉间皱痕 提交于 2019-12-17 19:52:31
问题 I'm learning about Angular change detection process and I'm checking the Chrome dev tools, I see strange behavior. My plnkr to demonstrate the behavior: http://plnkr.co/edit/cTLF00nQdhVmkHYc8IOu I have a simple component view: <li *ngFor="let item of list">{{item.name}}</li> and the its constructor: constructor() { this.list = [{name: 'Gustavo'}, {name: 'Costa'}] to simulate a simple request I've added: // simulating request repaint the DOM setInterval( () => { this.list = [{name: 'Gustavo'},

how to disable angular2 change detection for 3rd party libraries

你。 提交于 2019-12-17 18:36:49
问题 I have google maps which triggers 100+ times per second change detection. how to disable change detection for this. Click here for map preview it will be even worse when using mouseover event. ngDoCheck() { console.log('do check', this.i++); } 回答1: I had the same issue, try injecting the NgZone class on your component constructor constructor(private zone: NgZone) { ) then, use the runOutsideAngular method from NgZone to put in a callback the draw method from google charts, do something like

Trigger update of component view from service - No Provider for ChangeDetectorRef

北城以北 提交于 2019-12-17 18:34:01
问题 I would like to udpate my application view, triggered by events from service. One of my services injects the ChangeDetectorRef. Compilation works, but I am getting an error in the browser when the App is bootstrapped: No provider for ChangeDetectorRef! . I thought I needed to add it to my AppModule, but I can't find any documentation that suggests it is in a module that I can import there. I tried adding the class itself to the import array, but that caused an error. I also got an error

Angular2 detect changes using value equivalence or reference equality?

坚强是说给别人听的谎言 提交于 2019-12-13 15:15:53
问题 I am using Angular2-RC.1 and I have seen a poor performance when I setup a component having large data. I have a tabular component (wrapping Handsontable) and I expose a bindable Input property called "data". This property is usually bound to a large array (around one hundred thousand rows). When I set my large dataset the change detection is causing a test of value equivalence over the whole array in the host component (not the owner of the input property). @Component({ selector: "ha

How to push and update deep nested values in angular2 and maintain ui state

三世轮回 提交于 2019-12-12 00:14:26
问题 i have a deeply nested array as follow mainarray[]:{ array1[]:{sub1_array1[]:{},sub2_array1:{}}, array2[] ... // and so on } since i am retriving main array on init how can i push sub2_array1 updated values? but since on change view renders and ui state is changed including some active class components. so how can i maintain that? i read something about pipes and changedetectorRef but can't figure out how to use it ? Thanks in advance. 回答1: Something is very wrong with your array/object. And