Created
May 10, 2018 09:06
-
-
Save SaurabhLpRocks/003ed1a3f911e7e50d6cc23a34459e8a to your computer and use it in GitHub Desktop.
Angular Performance tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {AfterViewInit, ChangeDetectorRef} from '@angular/core'; | |
| @Component(…) | |
| class AppComponent implements AfterViewInit { | |
| constructor(private cdr: ChangeDetectorRef) {} | |
| ngAfterViewInit() { | |
| // We only want to detach the change detectors after change detection has been | |
| // performed for the first time | |
| this.cdr.detach(); | |
| } | |
| update() { | |
| // Run change detection only for this component when update() method is called. | |
| this.cdr.detectChanges(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {enableProdMode} from '@angular/core'; | |
| if (ENV === 'production') { | |
| enableProdMode(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var compression = require('compression') | |
| var express = require('express') | |
| var app = express() | |
| app.use(compression()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| selector: 'app', | |
| template: `<ul> | |
| <li *ngFor="let item of items; trackBy: trackById">{{item.name}}</li> | |
| </ul>` | |
| }) | |
| class AppComponent { | |
| Items = [ | |
| { | |
| id: 1, | |
| name: 'item 1' | |
| }, { | |
| id: 2, | |
| name: 'item 2' | |
| }, | |
| ... | |
| ]; | |
| trackById(index, item) { | |
| return item.id; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment