Wednesday 28 June 2017

Ionic 3 and Angular 4 connection with a REST web service


Announcement of Ionic 3

Wait, the Ionic 2 has just been launched a few months ago, is not it? Do not worry! Ionic 3 is Ionic 2 with some break changes. Like Angular, which arrives at its 4th version a few days ago, which means that when some updates require structural changes, the number of major versions increases accordingly.
This version comes with support for Angular 4 and an experimental support for Lazy Loading. 
More details on the Ionic blog:  http://blog.ionic.io/ionic-3-0-has-arrived/ 

Create desktop applications with Ionic Split Pane and Grid


Create applications that work on a mobile, tablet, and now desktop application with the new Ionic Split Pane and Grid controls. We are getting closer to our vision of an ionic application running wherever your users are, and these two components are major pieces of this puzzle.

Discover  Split Pane  and the new  Responsive Grid ! 
The Ionic 3 is still in beta. Before you start, you have to make a checklist.

- Node.js already installed with the command prompt.

- Ionic must be updated with this command.
npm install -g ioni

Create an Ionic 3 application

Always like the previous version of Ionic. Type this command to create a new Ionic 3 application.

ionic start ionic3 --v2
This command always uses the prefix "--v2", but do not worry if you check the dependencies in "package.json", you will see the difference.
Now you have to place yourself, with the command prompt, in the folder of your project (ionic3) and run on the browser after typing this command.
ionic serve -l

You are going to have an ionic 3 project with 3 tabs: Home, about and contact.

In this project we will try to display a list of countries that exist in this link which displays the data in JSON format:  https://restcountries.eu/rest/v2/all 

Ionic 3: connection with a REST web service


First, to be able to access a REST API, we must create a service or a Provider by this command.

ionic g provider rest
You will get a folder provider in which there is a file rest.ts
Open this file and put the following code in this file:
Import { Injectable } from '@ angular / core' ;
Import { Http } from '@ angular / http' ;
Import 'rxjs / add / operator / map' ;
@ Injectable ()
Export class Rest
{
Constructor ( public http : Http )
{
This . Http = http ;
}
GetAll ()
{
Return this . Http . Get ( 'https://restcountries.eu/rest/v2/all' ). Map ( res => res . Json ());
}
}
We need to register "HttpModule" in "app.module.ts", add this import to "app.module.ts".
import { HttpModule } from '@angular/http';
In the @NgModule imports section, add "HttpModule" so that it looks like this.
imports: [
  BrowserModule,HttpModule,
  IonicModule.forRoot(MyApp)
  ],
Always in "app.module.ts", save the Provider "Rest" first.
import { Rest } from '../providers/rest';
In the @NgModule providers section, add "Rest".
providers: [
  StatusBar,
  SplashScreen,
  {provide: ErrorHandler, useClass: IonicErrorHandler}, Rest
 ]
Now it's time to display the list of countries in the Home page. First, we need to change "home.ts" and put this code.
Import { Component } from '@ angular / core' ;
Import { NavController } from 'ionic-angular' ;
Import { Rest } from '../../providers/rest' ;
@ Component ({
Selector: 'page-home' ,
TemplateUrl: 'home.html'
})
Export class HomePage {
Items : string [];
Constructor ( public navCtrl : NavController , public rest : Rest ) {
This . GetPays ();
}
GetPays ()
{
This . Rest . GetAll (). Subscribe ( res => {
This . Items = res ;
});
}
}
Now change the code of the home.html file and put this code:
< Ion-header >
< Ion-navbar >
< Title-title > Home </ ion-title >
</ Ion-navbar >
</ Ion-header >
< Ion-content padding >
< Ion-list >
< Ion-item * ngFor = "let item of items" >
< Ion-avatar item-left >
< Img src = "{{item.flag}}" >
</ Ion-avatar >
< H2 > Country: </ h2 > < h2 > {{item.name}} </ h2 >
< P > Capital: {{item.capital}}, Region: {{item.region}} </ p >
</ Ion-item >
</ Ion-list >
</ Ion-content >

Wednesday 29 March 2017

Angular 4 Is here? With New Features.



Angular 4.0.0, the latest upgrade to the popular JavaScript framework for mobile and desktop development, was released by Google recently. This is a major release which has some breaking changes!
The upgrade features view engine improvements making Angular smaller and faster and helping developers build smaller applications. These changes should reduce the size of the generated code for your components by more than half in some cases.”
Version 4.0.0 follows a release schedule detailed late last year in which the company jumped right from Angular 2, which arrived last September, to Angular 4. The framework was rewritten with TypeScript, Microsoft’s typed superset of JavaScript, with the Angular 2 release, and version 4 uses TypeScript 2.1. Moving to the newer version of TypeScript means better type-checking throughout an application as well as better speed for ngc, the compiler for Angular templates.
Angular version 4.0.0 — invisible-makeover — is now available. This release is backwards compatible with 2.x.x for most applications.
Some notable features of this version include: template binding syntax improvements, TypeScript 2.1 and 2.2 compatibility, and source maps for temples.
Must Read : Reasons to choose Angualr JS for your next development project.
Going forward, developers can expect patch updates and ongoing work on version 4.1. The team is still creating a roadmap for the next six months. According to its release schedule, version 5.0 is expected in the fall of 2017 with version 6.0 being released March of 2018. Angular 4 Beta 5 version is released. Check out the new changes : https://angular.jsnews.io/on-the-road-to-angular-4-beta5-via-jaxentercom-angularjs-tech-development/
The beta phase officially began in mid-December 2016 and has rapidly gone through six beta versions (beta.5 was released on January 25)
The sixth beta version consists of 11 bug fixes and eight new features.
Angular 4 Beta 1 was released in December.
In November 2016, Google surprised everyone when it detailed plans for Angular 3 to be released a short six months after Angular 2’s arrival. Now it turns out there will be “No Angular 3“ release after all. Instead, “Google will go right to version 4“ of its popular JavaScript framework in March 2017.
Google’s Igor Minar said at the recent NG-BE 2016 Angular conference in Belgium that Google will jump from version 2 to version 4 so that the number of the upgrade correlates with the Angular version 4 router planned for usage with the release.
Minar, in fact, laid out a road map that has eight beta releases of Angular 4 coming out between December and February, followed by two release candidates in February and the general release on March 1. But Minar cautioned against getting too hung up on numbers and advised that the framework simply is called “Angular” anyway. “Let’s not call it AngularJS, let’s not call it Angular 2,” he said, “because as we are releasing more and more of these versions, it’s going to be super-confusing for everybody.”

Tentative Angular 4 release schedule

The fact that breaking changes will arrive, doesn’t mean they will arrive every other week. The Angular team committed to time-based releases that occur in three cycles:
— patch releases every week,
 — 3 monthly minor release after each major release and
 — a major release with easy-to-migrate-over breaking changes every 6 months.

Angular is on an aggressive schedule that would have Angular 5 arriving in September/October 2017, followed by six months by Angular 6, with Angular 7 coming six months later in September/October 2018. The next 3 months will be dedicated to finalizing Angular 4.0.0. Angular 4 features and release date
Google’s goals for Angular 4 are to be as backward-compatible with Angular 2 as possible and to improve compiler error messages. In November, Google talked about the next version of Angular, then known as version 3, emphasizing improvements in tooling as well as reduced code generation.
Angular’s upgrade plan also includes moving to TypeScript 2.1 as a baseline, away from TypeScript 1.8. While this means there are breaking changes, Minar was reassuring. “It’s not going to be a big deal.
We did these migrations across the whole Google and it was quite trivial, but it does require [some interventions].” Angular 2 was rewritten in TypeScript, Microsoft’s typed superset of JavaScript.
Earlier this month, Google released Angular 2.3, a minor upgrade featuring Angular Language Service, which is designed to integrate with IDEs and provide type completion and error-checking with Angular JS developmentTemplates.
Object inheritance for components is featured as well. Angular 2.2 arrived in November, featuring ahead-of-time compilation compatibility.