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.
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.
Top comments (4)
Also you can use instanceof operator instead of component.constructor.name
component.constructor.name === 'MyComponent'
--->>>
component instanceof MyComponent
instanceof not usefull
I think you need to change the producation settings for "sourceMap" to true
Source maps are helpful for debugging code, and this would not needed here in this regard. check out updated post here.