issues and solution Archives - Learn Smart Coding https://blogs.learnsmartcoding.com/category/angular/issues-and-solution/ Everyone can code! Sun, 05 Apr 2020 22:46:05 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 209870635 How to reset the selected file with input tag file type in Angular 9 https://blogs.learnsmartcoding.com/2020/04/05/how-to-reset-the-selected-the-file-with-input-tag-file-type-in-angular-9/ https://blogs.learnsmartcoding.com/2020/04/05/how-to-reset-the-selected-the-file-with-input-tag-file-type-in-angular-9/#respond Sun, 05 Apr 2020 22:46:05 +0000 https://karthiktechblog.com/?p=459 In this short post, I will show how to reset the selected file with the input tag file type in Angular 9. The usage of file input in HTML is more common. It is always good to reset or clear the selected files after a successful process of the file on the server-side. Input File: […]

The post How to reset the selected file with input tag file type in Angular 9 appeared first on Learn Smart Coding.

]]>
In this short post, I will show how to reset the selected file with the input tag file type in Angular 9. The usage of file input in HTML is more common. It is always good to reset or clear the selected files after a successful process of the file on the server-side.

Input File: HTML Code for Angular 9

<form [formGroup]="form">
  <div class="form-group">
    <label for="file"></label>
    <input type="file" #fileInput formControlName="fileContact" id="file" required
      (change)="handleFileInput($event.target.files)">
    <button type="button" class="btn btn-info" (click)="clearSelection()">Clear</button>
  </div>
</form>

Now by using the template variable “fileInput“, we can access the HTML element to clear the files.

How to reset the selected file with input tag file type in Angular 9
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

 @ViewChild('fileInput', {static: false})
  myFileInput: ElementRef;

Import ViewChild and ElementRef to support this functionality.

Using this template variable, clear the files.

this.myInputVariable.nativeElement.value = '';

Related Post

Looking for a complete example? read this post How to upload a file from Angular 9 with .NET Core Web API

Reference

Read more on Template syntax

Conclusion

In this post, I showed how to reset the selected file with the input tag file type in Angular 9. That’s all from this post. If you have any questions or just want to chat with me, feel free to leave a comment below.

The post How to reset the selected file with input tag file type in Angular 9 appeared first on Learn Smart Coding.

]]>
https://blogs.learnsmartcoding.com/2020/04/05/how-to-reset-the-selected-the-file-with-input-tag-file-type-in-angular-9/feed/ 0 459
How To Fix Your Angular App To Make it work in IE11 https://blogs.learnsmartcoding.com/2020/03/04/how-to-fix-your-angular-app-to-make-it-work-in-ie11/ https://blogs.learnsmartcoding.com/2020/03/04/how-to-fix-your-angular-app-to-make-it-work-in-ie11/#comments Wed, 04 Mar 2020 18:42:58 +0000 https://karthiktechblog.com/?p=412 Introduction In this short post, I will show How To Fix Your Angular App To Make it work in IE11. In Angular CLI version 8 and higher, applications are built using differential loading, a strategy where the CLI builds two separate bundles as part of your deployed application. The first bundle contains modern ES2015 syntax, takes […]

The post How To Fix Your Angular App To Make it work in IE11 appeared first on Learn Smart Coding.

]]>
Introduction

In this short post, I will show How To Fix Your Angular App To Make it work in IE11.

In Angular CLI version 8 and higher, applications are built using differential loading, a strategy where the CLI builds two separate bundles as part of your deployed application.

  • The first bundle contains modern ES2015 syntax, takes advantage of built-in support in modern browsers, ships less polyfills, and results in a smaller bundle size.
  • The second bundle contains code in the old ES5 syntax, along with all necessary polyfills. This results in a larger bundle size, but supports older browsers

Problem Statement

After Angular version 2, many things have changed. You app with version 2 or 4 might have worked in IE and when you upgraded your app to 6 or 8 then the IE stopped working. You might have come across many website stating this is because of Polyfills. That’s not the case always

Polyfills

Angular is built on the latest standards of the web platform. Targeting such a wide range of browsers is challenging because they do not support all features of modern browsers. You compensate by loading polyfill scripts (“polyfills”) for the browsers that you must support.

Angular.IO

Read about browser-support

So for specific use case, Polyfill might work. However, for supporting IE, you need two change to your configuration. Let’s see what are those to make this IE work both when debugging and after deploying to production.

Solution

Add a property  "es5BrowserSupport": true in angular.json file

How To Fix Your Angular App To Make it work in IE11
IE 11 Support

Now, change your target as "es5" in tsconfig.json file

support IE11 for angular app
IE 11 support

Also see other common issues encountered by developers.

Entity Framework Core dbcontextoptionsbuilder does not contain a definition for usesqlserver – Solved

Conclusion

Thanks for reading this piece. As you can see, to support IE 11, you need to add es5BrowserSupport property in angular.json file and change the target as es5 in tsconfig.json file that solved the problem. Let me know in the comments if you have questions.

The post How To Fix Your Angular App To Make it work in IE11 appeared first on Learn Smart Coding.

]]>
https://blogs.learnsmartcoding.com/2020/03/04/how-to-fix-your-angular-app-to-make-it-work-in-ie11/feed/ 1 412