How to do Empty Cache and Hard Reload from js in Angular?

When I publish updates of my application I wish to be sure that all files .js, .png and so on will be downloaded with status 200, not 304. I tried to use this method: window.location.reload(true); But after it one can see that some files are still downloaded with 304 status. How to do Empty Cache […]

By mr blond
Published
Categorized as angular, caching, html, javascript, reload Tagged , , , ,

How do I throw an error in a component and handle it in ErrorHandler?

There is my interceptor class, it should check if an error status is 401 and if it is it calls signOut() method from a service, if it isn’t does nothing: @Injectable() export class MyErrorHandler implements ErrorHandler { constructor( private UserService: UserService, ) { } handleError(error) { if (error?.status === 401) { this.UserService.signOut(); } } } […]

Ho do I use setTimeout with typescript?

There is a sample of setTimeout using in angular and typescript: let timer: number = setTimeout(() => { }, 2000); On compilation I get this message: error TS2322: Type ‘Timeout’ is not assignable to type ‘number’. Ho do I use setTimeout with typescript? Source: Angular Questions

By mr blond
Published
Categorized as angular, javascript, timeout, typescript Tagged , , ,

How to use the animation trigger from separate .ts file in Angular?

There is an example of exporting an animation trigger in Angular: import { animation, style, animate, trigger, transition, useAnimation } from ‘@angular/animations’; export const triggerAnimation = trigger(‘openClose’, [ transition(‘open => closed’, [ useAnimation(transitionAnimation, { params: { height: 0, opacity: 1, backgroundColor: ‘red’, time: ‘1s’ } }) ]) ]); But I can’t figure out how do […]

By mr blond
Published
Categorized as angular, animation, css, html, javascript Tagged , , , ,

Ho to use conditional class and class with variable with ngClass in Angular?

There is two classes should be upplied to the same div: <div [ngClass]="[‘class_01_’+someVar, {‘class_02’: isSelected}]><div> I get the error: Error: NgClass can only toggle CSS classes expressed as strings, got [object Object] Ho to use conditional class and class with variable with ngClass in Angular? Source: Angular Questions

By mr blond
Published
Categorized as angular, css, html, ng-class Tagged , , ,

How to type a variable for ngfor for html template in Angular?

I have this variable in my component: sizes: {[key: string]: GoodModel[]}; And in the controller my IDE handle this well. For instance one can type: this.sizes[‘5′][0].brand; Then you press f12 on brand for example and IDE shows the brand field of GoodModel class. But it doesn’t work when I do *ngFor in HTML: <div *ngFor="let […]

By mr blond
Published
Categorized as angular, html, javascript, ngfor, typescript Tagged , , , ,

How to handle undefined when passing data with Input in Angular?

A component colled with passing value with Input(): <app-available-modal [good]="’test’"></app-available-modal> The component looks like: @Component({ selector: ‘app-available-modal’, templateUrl: ‘./available-modal.component.html’, styleUrls: [‘./available-modal.component.scss’] }) export class AvailableModalComponent implements OnInit { @Input() good: TyreGoodModelTemp; constructor() { console.log(this.good); } ngOnInit(): void { console.log(this.good); } } I expect "test" and "test" output in the console. And the console.log from ngOnInit() […]

By mr blond
Published
Categorized as angular, binding, input, javascript, ngoninit Tagged , , , ,

Ho do I handle an event when one of the markers is clicked on leaflet?

I use leaflet for angular and there is an example of handling layer events. A template from this example: <div leaflet style="height: 300px;" [leafletOptions]="options" (leafletClick)="handleEvent(‘click’, $event)" (leafletMapMoveEnd)="handleEvent(‘mapMoveEnd’, $event)" (leafletMapZoomEnd)="handleEvent(‘mapZoomEnd’, $event)"> <div [leafletLayer]="baselayer" (leafletLayerAdd)="handleEvent(‘layerAdd’, $event)"> </div> </div> I’ve added markers to a layer: options = { layers: [ tileLayer(‘http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png’, { maxZoom: 18, attribution: ‘…’ }), marker([ […]

By mr blond
Published
Categorized as angular, javascript, leaflet Tagged , ,

Angular how do I resolve Error: Cannot match any routes. URL Segment: ‘catalog/test’?

There is a route: export const appRoutes: Routes = [ {path: ‘catalog’, component: DiskComponent}, {path: ‘catalog/**’, component: DiskComponent}, ] The path http://localhost:4200/catalog works, but when I open http://localhost:4200/catalog/test I get the error: Error: Cannot match any routes. URL Segment: ‘catalog/test’ How do I resolve it? Source: Angular Questions

By mr blond
Published
Categorized as angular, javascript, path, routes, url Tagged , , , ,

Angular ngFor renders nothing if array[0] = undefined

There is an array: var stringArray = new Array(); stringArray[1] = ‘one’; And ngFor renders nothing in angular when stringArray[0] = undefined. How do I solve it? Source: Angular Questions

By mr blond
Published
Categorized as angular, arrays, javascript, ngfor, typescript Tagged , , , ,

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq