mardi 14 mars 2017

Convert from 1.x to Angular 2.0

- Angular 1.x was not built with mobile support But in Angular 2 we have a Support for native mobile rendering in Android and iOs.
- Angular 1.x is in JavaScript but Angular 2 provides more choice for languages : ES5, ES6, TypeScript or Dart to write Angular 2 code.


- In Angular 1.x we work using controllers and $scope but they doesn't used anymore in  AngularJS 2
This is an example : 

We will use TypeScript for convertion.

Angular 1.x Controller

var myApp = angular
   .module("myModule", [])
   .controller("clientController", function($scope) {
     var clients = { firstname: "Hamida", lastname: "Rebai", Reference: 12 };
     $scope.clients = clients;
}); 

Component-Based

Angular 2 Components using TypeScript

import { Component } from 'angular2/core';

@Component({
  selector: 'clientsdata',
  template: '
    <h3>{{clients.firstname}}</h3> '
})

export class ClientComponent {
  clients = { firstname: "Hamida", lastname: "Rebai", Reference: 12 };
}


In template  we can call a html page like this :
 templateUrl: './app.component.html',
And we can mention the Css Class related to this page like this :
styleUrls: ['./app.component.css']
@Component annotation adds the metadata to the class and it's a new word in Angular 2.
Controllers to Components

Directives

Directive ng-app 
Directive ng-app designates the root element in an application, it's placed usually in root DOM element like : <body> or <html> tags.

Angular 1.x

<script>
   angular.element(document).ready(function() {
      angular.bootstrap(document, ['myApp']);
   });
</script>
Angular 2
We can Say Bye Bye ng-app because we will bootstrap angular only with code :
import { bootstrap } from 'angular2/platform/browser';
import { ClientComponent } from './client.component';
 
bootstrap(ClientComponent);
bootstrap function in our case is used to start component, it's also the root (parent) component of your AngularJS App.
Structural directives 

Angular 1.x structural directives

<ul>
   <li ng-repeat="client in clients">
     {{client.firstname}}
   </li>
</ul>
<div ng-if="clients.length">
   <h3>You have {{clients.length}} clients.</h3>
</div>

Angular 2 structural directives

<ul>
  <li *ngFor="#client of clients">
    {{client.firstname}}
  </li>
</ul>
<div *ngIf="client.length">
  <h3>You have {{client.length}} clients.</h3>
</div>
We can use the word let instead of #
<li *ngFor="let client of clients"> 
Structural Built-In Directives
==>Asterisk(*) sign is used as prefix for structural directives
==> For filters we keep using the same syntax (|) the pipe.


Removes the Need for Many Directives

Angular 1.x


<div ng-style="vm.strory ? {visibility :'visible' } : {visibility :'hidden' }>
<img ng-src="{{vm.imagePath}}">
<br/>
<a ng-href="{{vm.link}}">
{{vm.story}}
</a>
</div>

Angular 2 

<div [style.visibility] = "story ? 'visible' : 'hidden' ">
<img [src] = "imagePath">
<br/>
<a [href] = "link"> {{story}}</a>
</div>
==>Angular 2 uses camelCase syntax for built-in directives. For example, ng-class is now ngClass and ng-model is now ngModel.

Interpolation

Angular 1.x

<h2> {{vm.client.firstname}}</h2>
vm is the context !

Angular 2 

<h2> {{client.firstname}}</h2>

1 Way Binding

I Angular 1.x, ng-bind is used for one way data binding, but with Angular 2 it is replaced with [property], where property is valid HTML DOM element property.

Angular 1.x

<h2 ng-bind="vm.client.firstname"></h3>

Angular 2 

<h2 [innerText]="client.firstname"></h3>
<div> [style.color] = "color">{{client.firstname}}</div>
==> Any HTML element property ! one way data binding is achieved via wrapping the properties with square brackets.

2 Way Binding

In Angular 1.x, ng-model is used for two way data binding, but with Angular 2 it is replaced with [(ngModel)].

Angular 1.x

<input ng-model="client.firstname"></input>

Angular 2 

<input [(ngModel)]="client.firstname"></input>

Event Binding

For events, parentheses is used and for properties, square brackets are used. 

Angular 1.x

<button ng-click="vm.log('click')" ng-blur="vm.log('blur')">OK </button>

Angular 2 

<button (click)= "log('click')" (blur) = "log('blur')">OK</button>

Removes the Need for Many Directives ==> Next ARTICLE :) 

lundi 13 mars 2017

Create an Angular 2 and .NET Core application using Visual Studio 2017



Angular 2 and .NET Core are new technologies making revolution in the programming. It's a Storm for web and .NET developers that let them working using flexible and easier technologies.
Angular 2 is a next generation cutting-edge cross-platform user interface framework build to create web applications.
.NET Core is a backend framework from Microsoft cross-platform so it is now available on Windows, Mac and Linux.
These two technologies  was used independently of each other, but now, they are combined together to build applications for any client/server platform. (frontEnd and Backend side).

The best way to get started learning Angular 2 and TypeScript is to clone an application starter, a minimalist Angular 2 app that has the full set up for Angular 2, with TypeScript and the module loader.

In Visual Studio 2015, we found a lot of samples to clone, to start but after the launch of Visual Studio 2017, creating Angular project is more easier.



  1. Prerequisite
  2. Install the templates
  3. Create the application
  4. Get ready !

Prerequisite

  • Visual Studio 2017 installed 
  • Version of the .NET Core SDK installed 
  • NodeJS version 6 or later


Install the templates

Open up a command prompt and type the following.

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*





Create the application

To create your new Angular2 and .NET Core app, change directory to an empty folder, then type :

dotnet new angular

Get ready !

The video to learn easier :






mercredi 8 mars 2017

lundi 27 février 2017

jeudi 16 février 2017

I'm Junior, I have a project from scratch, Advice ?

Students in the end of their studies have to do a project from scratch, sometimes, for financial problems, companies choose a Junior developer to build some solutions from Scratch, for a junior with small experience, this will be a big challenge !
So, tell me please, how can I proceed ?
I have a specification, list of functionalities, maybe some mock-ups maybe not ! The domain is clear, but how can I start ? How can I engine things ? How can I estimate the duration of my work ?
Some developers start coding, designing Database and they finish by being blocked because there is no strategy.
This is my advice dear developers and students, if I was a teacher, I start by doing brainstorming, this is a case study, and I ask my students how they are able to start !
The first think to choose is your architecture : is it MVC, 3-tier, NLayered, MVP, MVVP.... and this depend from the project !
The second think is that we should follow Design principles in our project like Simplicity, Modular Design, Tolerance, Test of Independent Invention, ....
And we finish by choosing the correct Design Pattern ! (Prototype, Singleton, ....)
Independently of the language to choose, this can be applied for any projects !
And before starting your development, please, choose the right methodology, I prefer Agile methodology : Scrum because you are able to stay in touch and produce / change every sprint, and your project will involve incrementally.
And before doing your conception and your sprint backlog, list of functionalities, read this ebook related to SOLID principles : https://lostechies.com/wp-content/uploads/2011/03/pablos_solid_ebook.pdf
These principles, when used appropriately, can improve the encapsulation and coupling of your application, making it more malleable and testable in the face of changing requirements.


vendredi 10 février 2017

vendredi 27 janvier 2017

Get Started with Angular 2 using VisualStudio 2015 TypeScript ASP.NET Core

Why AngularJs 2.0 :

See original image

The first question is : what's new in Angular 2 ? or the difference between current version and the last one ?

We start by a simple answer : nothing ! Oh Really !
Angular 2 is a complete rewrite of the previous one, all previous versions are based on JavaScript but the current version is entirely based upon TypeScript (https://www.typescriptlang.org) and ECMAScript 6 specification (http://es6-features.org/) .
But why this rewrite ?
If we say ReactJs and EmberJs  we answer theses are excellent JS libraries as competitor for Angular.
Angular 2 is a new approach, easy to write and readable syntax so more sample than the previous versions especially for developer that used it and was face many problems and breaking changes in code syntax or in the way of thinking and designing a client application.
Angular 2 give the developer the toolbox needed to build reactive, cross-platform web-based apps.

During this trainning we will discover Angular 2 using VisualStudio 2015 TypeScript ASP.NET Core.
1- Prerequisites