wtorek, 27 lutego 2018

How to reload current page by clicking link again in Angular

In .component.ts file add to constructor:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    this.router.routeReuseStrategy.shouldReuseRoute = function() {
      return false;
    }
    this.router.events.subscribe((evt) => {
      if (evt instanceof NavigationEnd) {
        // trick the Router into believing it's last link wasn't previously loaded
        this.router.navigated = false;
        // if you need to scroll back to top, here is the right place
        window.scrollTo(0, 0);
      }
    });

Router and NavigationEnd must be imported:


1
import { Router, NavigationEnd } from '@angular/router';


source: https://github.com/angular/angular/issues/13831

środa, 21 lutego 2018

How to solve TypeError: date.split is not a function in JHipster

If you get:
ERROR TypeError: date.split is not a function
    at JhiDateUtils.toDate

probably you have to add date transform in PopupService.

Date format should be like: 2018-02-12T13:05:54

Change:

1
2
3
4
5
            if (id) {
                this.barCashupService.find(id).subscribe((barCashup) => {
                    this.ngbModalRef = this.barCashupModalRef(component, barCashup);
                    resolve(this.ngbModalRef);
                });

to:

1
2
3
4
5
6
7
8
9
            if (id) {
                this.barCashupService.find(id).subscribe((barCashup) => {
                    barCashup.barmanLoginTime = this.datePipe
                        .transform(barCashup.barmanLoginTime, 'yyyy-MM-ddTHH:mm:ss');
                    barCashup.cashupTime = this.datePipe
                        .transform(barCashup.cashupTime, 'yyyy-MM-ddTHH:mm:ss');
                    this.ngbModalRef = this.barCashupModalRef(component, barCashup);
                    resolve(this.ngbModalRef);
                });


Or if you call entity from function, change:


1
2
3
4
5
  loadLastCashup() {
    this.newDayService.query().subscribe((cashup) => {
      this.lastCashup = cashup;
    });
  }

to:

1
2
3
4
5
6
7
8
9
  loadLastCashup() {
    this.newDayService.query().subscribe((cashup) => {
      this.lastCashup = cashup;
                    this.lastCashup.barmanLoginTime = this.datePipe
                        .transform(this.lastCashup.barmanLoginTime, 'yyyy-MM-ddTHH:mm:ss');
                    this.lastCashup.cashupTime = this.datePipe
                        .transform(this.lastCashup.cashupTime, 'yyyy-MM-ddTHH:mm:ss');
    });
  }



czwartek, 8 lutego 2018

środa, 7 lutego 2018

How to add translated string to JHipster Angular5 .ts file

Let’s assume we have already language files in /src/main/webapp/i18n/


In .component.ts file import:


 import { TranslateService } from '@ngx-translate/core';

Add to constructor:


1
       private translateService: TranslateService,


Then translated string is:


const translatedString=this.translateService.instant("global.menu.entities.substitute");