Libetia A

Libetia A

1569639239

How do support Internet Explorer in Angular 8

For some strange reason, the world has not yet forgotten Internet Explorer. If you’re a front-end developer, this is a very stressful truth, especially if Angular is your favorite front-end framework.

As you probably know, Angular supports Internet Explorer until version 9, but you need to use some “polyfill” scripts. If you use the CLI, and I hope that you are not starting projects without CLI still, you already have a polyfills.ts in your src folder. This file contains some mandatory polyfills like “zone.js”, and some optional imports, commented by default, based on the needs of your project.

In the latest Angular major release (8.x.x), the team introduced a new feature named “differential loading”, that creates two packages when you build your project: one for the modern browser using the ES2015 syntax with no need of polyfills, and one, larger than the first, that contains polyfills and uses the ES5 syntax to support old browsers.

This is image title

How does this feature work? How the browser chooses the correct bundle? It is simpler than you think: the index.html points all the files and uses the attributes nomodule and type=”module” to understand if the browser support ES modules. All modern browsers only download the scripts with the attribute type=”module”. Legacy browsers, instead, do not know this attribute and download files with nomodule attributes. Actually, some old browsers download all the files, but they only execute the correct ones.

This is image title

This feature works fine with the build command, but with the serve, test and e2e commands, only the es2015 bundles are created. So, if we execute the classic ng serve command to test our application in development mode, we can’t test it with Internet Explorer. We can solve this problem changing our tsconfig.json “target” property to “es5” instead of “es2015”, but if we want to maintain both the configurations we can add a “tsconfig-es5.app.json” in our root folder with this configuration:

{
 "extends": "./tsconfig.app.json",
 "compilerOptions": {
   "target": "es5"
 }
}

Now we can use the angular.json to add a new configuration to our project. In the “build” and “serve” sections, we need to add a new “es5” configuration, to specify the new tsconfig created, and the use of it in the “serve” command:

"build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": { ...
    },
    "configurations": {
        "production": { ...
        },
        "es5": {
            "tsConfig": "./tsconfig-es5.app.json"
        }
    }
},
"serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": { ...
    },
    "configurations": {
        "production": { ...
        },
        "es5": {
            "browserTarget": "IEdemo:build:es5"
        }
    }
}

We can then run our project in development mode with the command:

ng serve --configuration es5

Is the problem solved therefore? Do we need anything else? It would be wonderful but it’s not so. We still need to test our application on Internet Explorer. If we are on a Windows platform, we can start Internet Explorer and test our application, whereas if we are on a Mac and we have a Parallels license, we can follow the instructions of one of articles Debugging Angular in Windows with Parallels and run the server on Mac, testing the application on a virtualized instance of Windows.

Using the Explorer emulation feature, we can test any old version of the browser:

This is image title

Let’s take an example. Usually, it can be convenient to use the attribute hidden instead of *ngIf to hide a piece of HTML, both for functional and for performance reasons. If we want to use a button to show or to hide a DIV element with the hidden attribute, we can write this simple code:

<button (click)="elementVisible = !elementVisible">
 Show/hide
</button>
<div [hidden]="elementVisible">
 <h1>
   Welcome to {{ title }}!
 </h1>
</div>

It works without problems with any modern browser and in IE11, but it doesn’t on IE10.

This is image title

We need an additional polyfill to add the hidden functionality to IE10, but, to implement it, we need to understand why hidden doesn’t work. If we apply manually the hidden attribute to the HTML element, the piece of the UI hides correctly. The problem is not the attribute hidden, but the Angular binding that doesn’t add the attribute if it doesn’t exist for the element. So, we need to add “hidden” attribute to the HTMLElement of the browser if it doesn’t exist, placing, for example, this code in an hidden-attribute-polyfill.ts and importing it in the main polyfills.ts:

((global: any) => {
 'use strict';
 
 const notInBrowser = !global.HTMLElement || !HTMLElement.prototype;
 const alreadyDefined = 'hidden' in HTMLElement.prototype;
 const notPossibleToImplement = typeof Object.defineProperty === 'undefined';
 
 if (notInBrowser || alreadyDefined || notPossibleToImplement) {
   return;
 }
 
 Object.defineProperty(HTMLElement.prototype, 'hidden', {
   get() {
     return this.hasAttribute('hidden');
   },
   set(value) {
     if (value) {
       this.setAttribute('hidden', '');
     } else {
       this.removeAttribute('hidden');
     }
 
     return value;
   },
 });
})(typeof window === 'undefined' ? this : window);

Now it works:

This is image title

You can find the sample code [here](https://github.com/apomic80/angular8-and-internet-explorer](https://github.com/apomic80/angular8-and-internet-explorer “here”)

Happy coding and thank for reading !

Originally published on blexin.com

#angular #angular-js #web-development

What is GEEK

Buddha Community

How do support Internet Explorer in Angular 8
Christa  Stehr

Christa Stehr

1598940617

Install Angular - Angular Environment Setup Process

Angular is a TypeScript based framework that works in synchronization with HTML, CSS, and JavaScript. To work with angular, domain knowledge of these 3 is required.

  1. Installing Node.js and npm
  2. Installing Angular CLI
  3. Creating workspace
  4. Deploying your First App

In this article, you will get to know about the Angular Environment setup process. After reading this article, you will be able to install, setup, create, and launch your own application in Angular. So let’s start!!!

Angular environment setup

Install Angular in Easy Steps

For Installing Angular on your Machine, there are 2 prerequisites:

  • Node.js
  • npm Package Manager
Node.js

First you need to have Node.js installed as Angular require current, active LTS or maintenance LTS version of Node.js

Download and Install Node.js version suitable for your machine’s operating system.

Npm Package Manager

Angular, Angular CLI and Angular applications are dependent on npm packages. By installing Node.js, you have automatically installed the npm Package manager which will be the base for installing angular in your system. To check the presence of npm client and Angular version check of npm client, run this command:

  1. npm -v

Installing Angular CLI

  • Open Terminal/Command Prompt
  • To install Angular CLI, run the below command:
  1. npm install -g @angular/cli

installing angular CLI

· After executing the command, Angular CLI will get installed within some time. You can check it using the following command

  1. ng --version

Workspace Creation

Now as your Angular CLI is installed, you need to create a workspace to work upon your application. Methods for it are:

  • Using CLI
  • Using Visual Studio Code
1. Using CLI

To create a workspace:

  • Navigate to the desired directory where you want to create your workspace using cd command in the Terminal/Command prompt
  • Then in the directory write this command on your terminal and provide the name of the app which you want to create. In my case I have mentioned DataFlair:
  1. Ng new YourAppName

create angular workspace

  • After running this command, it will prompt you to select from various options about the CSS and other functionalities.

angular CSS options

  • To leave everything to default, simply press the Enter or the Return key.

angular setup

#angular tutorials #angular cli install #angular environment setup #angular version check #download angular #install angular #install angular cli

Clara  Gutmann

Clara Gutmann

1598716260

Angular 8 CRUD Example | Angular 8 Tutorial For Beginners

Angular 8 CRUD is a basic operation to learn Angular from scratch. We will learn how to build a small web application that inserts, read data, update and delete data from the database. You will learn how to create a MEAN Stack web application. In this Angular 8 Tutorial Example, you will learn a new framework by building a crud application.

New features of Angular 8

You check out the new features in brief on my  Angular 8 New Features post.

I have designed this Angular 8 CRUD Tutorial, especially for newcomers, and it will help you to up and running with the latest version of Angular, which is right now 8.

#angular #angular 8 #angular 8 crud

Shawn  Durgan

Shawn Durgan

1604050560

Are the days of Internet Freedom Numbered?

In an ideal digital world, everyone has open access to the Internet.

In that world, all traffic is treated equally without any blocking, prioritization, or discrimination.

That ideal world is one where there is widespread support for an open Internet that ensures that publicly available information is equally transmittable from - and accessible to - all people and businesses.

An open network ensures equal accessibility. Network (net) neutrality is a principle based on the idea that all communications on the Internet should be treated equally. It opposes any potential power that some organizations may have to implement different charges or vary service quality. Such actions can be based on a set of factors that include content, platform, application type, source address, destination address or communication method.

In essence, net neutrality demands that all data on the Internet travels over networks in a fair way that ensures that no specific sites, services or applications get favourable service in terms of speed or bandwidth. It also ensures that all traffic - no matter where it’s from - gets the same service.

Is the Internet fair?

The Internet is simply a network of computers sharing information.

A better question to ask would be if ISPs are acting in a fair way.

As the intermediaries between users and the sources of information on the Internet, some large-scale ISPs wield a great deal of power.

Some have been known to tamper with traffic using “middleware” that affects the flow of information. Others act as private gatekeepers that subject content to additional controls throughout the network by giving optimal bandwidth to certain sites, apps and services while slowing down or completely blocking specific protocols or applications.

#internet-day #net-neutrality #open-internet #internet #fix-the-internet #history-of-the-internet #internet-censorship

Clara  Gutmann

Clara Gutmann

1598727360

Angular 8 Updates And Summary of New Features

Angular 8 Updates And Summary of New Features is today’s topic. Angular 8 arrives with an impressive list of changes and improvements including the much-anticipated Ivy compiler as an opt-in feature. You can check out  Angular 7 features and updates if you have not seen yet. In this blog, we have written some articles about  Angular 7 Crud,  Angular 7 Routing,  Angular ngClass,  Angular ngFor.

Angular 8 Updates And Summary

See the following updates.

TypeScript 3.4

Angular 8.0 is now supported TypeScript 3.4, and even requires it, so you will need to upgrade.

You can look at what  TypeScript 3.3 and  TypeScript 3.4 brings on the table on official Microsoft blog.

#angular #typescript #angular 7 crud #angular 7 routing #angular 8

Roberta  Ward

Roberta Ward

1593184320

Basics of Angular: Part-1

What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular.

Angular is a Typescript-based open-source front-end web application platform. The Angular Team at Google and a community of individuals and corporations lead it. Angular lets you extend HTML’s syntax to express your apps’ components clearly. The angular resolves challenges while developing a single page and cross-platform applications. So, here the meaning of the single-page applications in angular is that the index.html file serves the app. And, the index.html file links other files to it.

We build angular applications with basic concepts which are NgModules. It provides a compilation context for components. At the beginning of an angular project, the command-line interface provides a built-in component which is the root component. But, NgModule can add a number of additional components. These can be created through a template or loaded from a router. This is what a compilation context about.

What is a Component in Angular?

Components are key features in Angular. It controls a patch of the screen called a view. A couple of components that we create on our own helps to build a whole application. In the end, the root component or the app component holds our entire application. The component has its business logic that it does to support the view inside the class. The class interacts with the view through an API of properties and methods. All the components added by us in the application are not linked to the index.html. But, they link to the app.component.html through the selectors. A component can be a component and not only a typescript class by adding a decorator @Component. Then, for further access, a class can import it. The decorator contains some metadata like selector, template, and style. Here’s an example of how a component decorator looks like:

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.scss']
})

Role of App Module

Modules are the package of functionalities of our app. It gives Angular the information about which features does my app has and what feature it uses. It is an empty Typescript class, but we transform it by adding a decorator @NgModule. So, we have four properties that we set up on the object pass to @NgModule. The four properties are declarations, imports, providers, and bootstrap. All the built-in new components add up to the declarations array in @NgModule.

@NgModule({
declarations: [
  AppComponent,
],
imports: [
  BrowserModule,
  HttpClientModule,
  AppRoutingModule,
  FormsModule
],
bootstrap: [AppComponent]
})

What is Data Binding?

Data Binding is the communication between the Typescript code of the component and the template. So, we have different kinds of data binding given below:

  • When there is a requirement to output data from our Typescript code in the HTML template. String interpolation handles this purpose like {{data}} in HTML file. Property Binding is also used for this purpose like [property] = “data”.
  • When we want to trigger any event like clicking a button. Event Binding works while we react to user events like (event) = “expression”.
  • When we can react to user events and output something at the same time. Two-way Binding is used like [(ngModel)] = “data”.

image for understanding data binding

#angular #javascript #tech blogs #user interface (ui) #angular #angular fundamentals #angular tutorial #basics of angular