constructor.name is not working in production

gaurangdhorda

GaurangDhorda

Posted on March 13, 2020

constructor.name is not working in production

In angular do not use constructor.name in production directly. When
ng build --prod fires to create production build of Angular app at the same time many techniques applied to create minimum size of build and improve performance of application. At this process webpack minifiere converts class name to short name, and thus you can not get real class name by constructor.name in production rather we get minified name of class and that is different. So to solve this we have to save class name in class property when creating class instance. This way we can maintain our class name logic in production build.

Below image is working fine in Development mode.

Alt Text

Below image is Working fine production mode. so we have changed our code for getting class name by setting up class proterties of class name.

Alt Text

💖 💪 🙅 🚩
gaurangdhorda
GaurangDhorda

Posted on March 13, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related