NgSwitch

<ng-container [ngSwitch]="row.promotion_type">
<span *ngSwitchCase="0">Coupon</span>
<span *ngSwitchCase="1">Instore</span>
<span *ngSwitchCase="2">Message</span>
</ng-container>

Intercept input property changes with ngOnChanges()

  1. import { Component, Input, OnChanges, SimpleChange } from '@angular/core';
  2.  
  3. @Component({
  4. selector: 'app-version-child',
  5. template: `
  6. <h3>Version {{major}}.{{minor}}</h3>
  7. <h4>Change log:</h4>
  8. <ul>
  9. <li *ngFor="let change of changeLog">{{change}}</li>
  10. </ul>
  11. `
  12. })
  13. export class VersionChildComponent implements OnChanges {
  14. @Input() major: number;
  15. @Input() minor: number;
  16. changeLog: string[] = [];
  17.  
  18. ngOnChanges(changes: {[propKey: string]: SimpleChange}) {
  19. let log: string[] = [];
  20. for (let propName in changes) {
  21. let changedProp = changes[propName];
  22. let to = JSON.stringify(changedProp.currentValue);
  23. if (changedProp.isFirstChange()) {
  24. log.push(`Initial value of ${propName} set to ${to}`);
  25. } else {
  26. let from = JSON.stringify(changedProp.previousValue);
  27. log.push(`${propName} changed from ${from} to ${to}`);
  28. }
  29. }
  30. this.changeLog.push(log.join(', '));
  31. }
  32. }

How to use paginator from material angular?

Source: https://stackoverflow.com/questions/45318164/how-to-use-paginator-from-material-angular

I'm struggling with the same here. But I can show you what I've got doing some research. Basically, you first start adding the page @Output event in the foo.template.ts:
 <md-paginator #paginator
                [length]="length"
                [pageIndex]="pageIndex"
                [pageSize]="pageSize"
                [pageSizeOptions]="[5, 10, 25, 100]"
                (page)="pageEvent = getServerData($event)"
                >
 </md-paginator>
And later, you have to add the pageEvent attribute in the foo.component.ts class and the others to handle paginator requirements:
pageEvent: PageEvent;
datasource: null;
pageIndex:number;
pageSize:number;
length:number;
And add the method that will fetch the server data:
ngOnInit() {
   getServerData(null) ...
}

public getServerData(event?:PageEvent){
  this.fooService.getdata(event).subscribe(
    response =>{
      if(response.error) {
        // handle error
      } else {
        this.datasource = response.data;
        this.pageIndex = response.pageIndex;
        this.pageSize = response.pageSize;
        this.length = response.length;
      }
    },
    error =>{
      // handle error
    }
  );
  return event;
}
So, basically every time you click the paginator, you'll activate getServerData(..) method that will call foo.service.ts getting all data required. In this case, you do not need to handle nextPage and nextXXX events because it will be automatically calculated upon view rendering.
Hope this can help you. Let me know if you had success. =]

How to compare a local git branch with its remote branch?

Source: https://stackoverflow.com/questions/1800783/how-to-compare-a-local-git-branch-with-its-remote-branch

If [remote-path] and [local-path] are the same, you can do
$ git fetch origin master
$ git diff origin/master -- [local-path]
git diff origin/master src/app/pages/check-in/check-in-list.component.ts



How do I exit the results of 'git diff' in Git Bash on windows?

I think pressing Q should work.

Note 1: The second command above will compare against the locally stored remote tracking branch. The fetch command is required to update the remote tracking branch to be in sync with the contents of the remote server. Alternatively, you can just do
$ git diff master:<path-or-file-name>
Note 2: master can be replaced in the above examples with any branch name

git diff <local branch> <remote>/<remote branch>
For example git diff master origin/master, or git diff featureA origin/next
Of course to have said remote-tracking branch you need to git fetch first; and you need it to have up to date information about branches in remote repository.

Pagination: Server Side or Client Side?

Source: https://dzone.com/articles/pagination-server-side-or-clie

Server side pagination is better for:
  • Large data set
  • Faster initial page load
  • Accessibility for those not running JavaScript
  • Complex view business logic
  • Resilience to concurrent changes
Client side pagination is better for:
  • Small data set
  • Faster subsequent page loads
  • Sort & filter requirements supported fully (unless results greater than max size).
To sum up, if you’re paginating for primarily cosmetic reasons, it makes more sense to handle it client side. And if you’re paginating to reduce initial load time, server side is the obvious choice. Of course, client side’s advantage on subsequent page load times diminishes if you utilize Ajax to load subsequent pages.

angular material 2 table header center alignment

Source: https://stackoverflow.com/questions/46154838/angular-material-2-table-header-center-alignment

Update for Angular Material 5.x.x, no need for ng-deep:
  mat-header-cell {
   display:flex;
   justify-content:flex-end;
  }

md-header-cell get 'translated' to a container with class="mat-sort-header-container". Using that, you set its style with ng-deep. Use flexbox to center its content. Put the following in the components stylesheet:
::ng-deep .mat-sort-header-container {
  display:flex;
  justify-content:center;
}

anti-pattern là gì

  Trong công nghệ và lập trình, Anti-pattern (mẫu phản diện) là những giải pháp bề ngoài có vẻ hiệu quả để giải quyết một vấn đề phổ biến, ...