Posts

Showing posts from September, 2022

How to use NgClass in angular?

Image
NgClass      The NgClass directive allows you to set the CSS class dynamically for a DOM element.      There are two ways to use this directive, the first is by passing an object literal to the                directive.            You can use NgClass using below syntax                               [ngClass]="{'text-success':true}"        When using an object literal, the keys are the classes which are added to the element if the value of the key evaluates to true. So in the above example, since the value is true this will set the class text-success onto the element the directive is attached to. The value can also be an  expression , so we can  re-write  the above to be. [ngCl...

While reloading the page I got 404 error for angular.

Image
       I am using  angular  application; I have no problem in running on localhost when I hosted my application on server. When I clicked the employee button it loads the employee details. However I refreshed the same page, It gives me  404 file  or directory not found error.                     I have fixed the issue using routing strategies(HashLocationStrategy) approach. This will make the links look like   http://domain.com/#/page  for the url   http://domain.com/page . In  app.module.ts , we need to import   HashLocationStrategy, LocationStrategy .  And then in NgModule Provider add   {{provide: LocationStrategy, useClass: HashLocationStrategy}} . App.Module.Ts import { BrowserModule } from  '@angular/platform-browser' ; import { NgModule } from  '@angular/core' ; import { HashLocationStrategy, LocationStrategy } from  '@angular/...