Skip to main content

Posts

Showing posts with the label Angular

What will happen if we apply the enableProdMode() in Angular?

Applying enableProdMode() in the Angular project will do the following things  * The Change Detection will check only once contrast to development mode is doing for 2 times * The configuration file will change to 'environment.prod.ts' (Not necessarily the same name, we can set different name in the angular.json file) * Turns off the assertions  * Turns off the regular checks in framework which is happening in development mode  * The performance will be relatively high compared to development mode 

Common issues with Angular Programming Development and Fixes

         Angular programmers may face these types of common errors all the way in their programming path, here are the few issues and fixes to them.          1) Can't bind to 'formGroup' since it isn't a known property of 'form'   The ReactiveFormsModule might be in missing in the app.module.ts imports section   Import the ReactiveFormsModule   imports:  [ ReactiveFormsModule ]   And don’t forgot to specify the imports import  {  ReactiveFormsModule  }  from   '@angular/forms' ;     2)          Can't bind to 'ngModel' since it isn't a known property of 'input'.   Cause: The FormsModule might be in missing in the app.module.ts imports section   Import the FormsModule        imports:  [      BrowserModule ,      AppRoutingModule ,      FormsModule   ],   And don’t forgot to specify the imports import  {  FormsModule  }  from   '@angular/forms' ;   3)          Nu

Angular *ngIf & else | Angular Tips

    Normally We will use the   *ngIf to show hide the controls by using following method             <div  *ngIf="showIf" >               <p>                 Showing the if part               </p>             </div> Where showIf needs to be declared in the component.ts file and it needs to be set as true in order to view that control   Like this showIf : Boolean;   in the constructor or in the ngIf   this. showIf – true;   For Else we need to create a ng-template and call in the else part like below   Please Note: the ng-template’s id should be unique   <div *ngIf="showIf; else  elsePart">   <p      Showing the if part   </p> </div>       <ng-template #elsePart>     <p>     Showing the else part   </p>  </ng-template>     Example Source can be found at : https://angular-ivy-5vysbz.stackblitz.io    

Angular: Constructor vs ngOnInit , Basic differences

  Angular: Constructor vs   ngOnInit, Basic differences   Constructor is the feature provided by ES6 (i.e. Typescript) ngOnInit is provided by Angular itself       interface OnInit {   ngOnInit(): void }   Before seeing what was the order of execution let’s see if both is not available what will happen,   You can see that the Angular s happily compiling and executing the code even the constructor or ngInit is not present           As a next step we are trying to implement the ngOnInit interface explicitly, let’s see what will happen       We are getting the following error   Class 'AppComponent' incorrectly implements interface 'OnInit'. Property 'ngOnInit' is missing in type 'AppComponent' but required in type 'OnInit'.   So we need to implement the ngOnInit if we are specifying in the class   After implementing the ngOnInit we are getting the page back to normal     So what is t