Sébastien Lucas / Dev wiki
  • Blog Wiki
  • Story book
  • Developers comics
  • Angular
    • Angular CLI + Angular.json
    • ngTemplateOutlet
    • Angular Schematic
    • Interceptor
    • Micro frontend + Mono repo
    • Build a library module
    • Error handling
    • Virtual and infinite scroll
    • Angular i18n
    • Debug Angular
    • Angular LifeCycle Hook
    • Nested forms in Angular
    • Angular Recipes
    • Master component in Angular
    • Perfomance optimization
    • Service Workers + PWA
    • Mobile
    • Electron app / Desktop app
    • Unit test & Angular
      • Unit test recipes (Jasmine / Karma / Angular)
      • Testing services with httpMock
    • Communication between components
    • Angular snippet library
    • Release and version management
    • Angular tutorial selection
    • UI components libraries
    • Angular libraries
    • Angular Tutorials
    • NGRX
      • Angular NGRX / Tips and code examples
      • Angular new Redux (alternative to ngrx)
      • NGRX unit test
      • Angular ngrx / Basics
    • Angular 2/Angular 1 differences
  • Graphql
  • Three.js
  • Ag grid
  • Open source BIM and 3D
  • Javascript
    • Null vs undefined
    • Html API
    • Await API
    • Debug memory leaks
    • Offline and PWA
    • Javascript tutorials
    • Javascript recipes
    • Bluebird missing docs
    • Alternative to lodash with ES6
    • ES6 syntax the best parts
    • Vanilla JS
  • RXJS
    • Docs
    • Recipes
    • Mock API and sandbox
    • Observables rxjs recipes
    • Combination operators
  • NODE.js
    • Environment variables
    • Fix CORS
    • Pagination requests in API
    • API tests
    • Node.js security
    • Learn node.js
    • Best libraries for node.js
    • Mongoose recipe
    • Debug node.js
  • Gatsby / React
    • Hooks
    • React concepts
    • Gatsby internationalisation
  • Ghost blog
  • Services for developers
    • SaaS images services
    • Airtable API examples
  • MISC
    • JIRA debugging
    • Wordpress plugins
    • Interview Sébastien Lucas
    • English expression
    • True recipes
    • Science podcast
  • AI
    • Machine learning open source
    • Tensor flow
    • Machine learning
    • Code examples
    • Courses and tutorials
    • Datasets
    • The Future of AI
    • Learn algo and data structures
  • Typescript
    • Generic types
    • Typescript recipes
    • Advanced types
      • Conditional types
      • Type guards
    • d.ts files
  • Docker
    • Starting with docker
    • Dockerise simple node app
    • Docker by aymen el amri
  • Mongodb
    • Pattern and data modeling
  • Devops
    • Heroku
    • Scaleway
    • Github template
    • Gitlab CI
    • http2
    • nginx
    • zsh
    • CI Continuous integration
    • DNS
    • Devops resources
    • Gcloud useful commands
    • Authenticate Gcloud
    • Documentation generators
    • Firebase database
  • Developers ressources
    • Online platform coding
      • Online courses
      • Coding games
      • Coding test platforms
      • Links to check
    • Good developers blogs
    • Nice open source project / github
  • Tooling
    • The chrome urls
    • Linux Mac tips
    • Webstorm configuration
    • Develop in Windows
    • Mac debug hardware
    • Mac Setup for a developer
    • Chrome extension
    • Develop toolbox
  • HTML / CSS
    • Tailwind
    • Css grid
    • ☘️Nice styles & generators
    • Favicon
    • Flexbox grid
    • Flexbox layout
    • PUG templates tips
    • Html and css references
    • Css snippets
    • SASS-CSS libraries
    • New things in scss
    • SASS best practices
    • Style lint
  • Tests
    • Cypress
      • Learn cypress and more tests
      • Cypress commands
      • Cypress plugins
      • Page object && app actions
      • Flaky tests
    • Mobile test
    • BDD + Cucumber
    • Puppeteer
    • Type of tests + Ressources
    • Jasmine test
    • Mock, fake, stub in unit tests
    • E2e tests with protactor
    • Mocha
  • REVIT & AEC tools
  • Git
    • Git commits
    • Git tips
    • Git hooks
    • Set up a mono repo
  • Design Pattern
    • Functional Programming
  • Job board / Remote jobs
  • SVG
  • JSON
  • Github
    • Forking a github repo
  • NPM
    • Private NPM packages
    • Publish to NPM with np
  • Yarn
    • Yarn evolution / 2, 3...
    • Yarn Linking
Powered by GitBook
On this page
  • Typescript
  • System.js and ES6 stuff
  • The ES6 modules
  • You need a package loader!
  • ES6 is not only syntax changes
  • Components everywhere
  • Components angular clear syntax
  • Css scoping / Web component like pseudo phantom DOM
  • Binding
  • Observable on top of promise
  • Debugging
  • Zone.js
  • Events

Was this helpful?

  1. Angular

Angular 2/Angular 1 differences

PreviousAngular ngrx / BasicsNextGraphql

Last updated 6 years ago

Was this helpful?

Angular 2 architecture have changed, but javascript too. The rise of ES6 is parallel to the release of angular 2. Angular choose to have dependencies on typescript though it is possible to use angular 2 without typescript

Typescript

Typescript is a superset of ES6. It means it has all features of ES6 plus additional features. The main differentiating feature is typings hence the name typescript But not only, it allows also to use the decorator syntax @ used by angular heavily.

At first I was not very enthusiastic to use Typescript, first because it is a software initiated by Microsoft and I kept with some bad opinions about this firm. But also because I kept with the idea typings was a thing for old fashioned java, c++ guys and was not useful in modern workflows.

I changed my mind, about Microsoft and about hard typings!

It could be really useful, and the best is that you can use it a lot or in a minimal way if you want. It allow you to intercept simple errors before compilation, which is not bad.

The drawbacks are :

  • you can have bugs only caused by typings stuff....

  • you need to compile back to a file readable by the browser but less readable by you. But anyway with ES6 we will be obliged to work like this, till ES6 will be readable directly in all browsers.

System.js and ES6 stuff

The ES6 modules

ES6 typescript introduce the javascript modules syntax import { myModule} from '../../file.js';

It is nice because it allow to define what each files need in a declarative style. The previous way to do that, was simply to add many scripts files in a html fil. Or concatenate a bunch of files in one files. But no explicit relations was set between those files.

With the modules, every file "require" / "import" the files it need to execute properly. If you practice Node.js you should be familiar with that and the really simple idea it is.

You need a package loader!

ES6 is not only syntax changes

Components everywhere

Components angular clear syntax

The component syntax is much, much clearer that in angular 1. By the way everything is component. That mean that no part of the page rendered by angular is not a component. That does not mean you need to over structure your app, with components, sub-components. It is up to you to be granular as it is useful for you

Css scoping / Web component like pseudo phantom DOM

Angular 2 introduce an elegant way to use component specific / phantom dom, without waiting for full browser support. Let's reacall what it is. Phantom DOM is a way to isolate the DOM of a component from the interior world so that global CSS do not impact it.

Let's take a simple example. You have a sidebar component, with it's style that you want everyone on the planet to be able to use, and also be sure that it's graphical appearance will be preserved.

Without phantom DOM, it is feasible, but you cannot garanty that the appearance of your component will be always preserved. Indeed the only way to style it in a secure way is to use a sort of name spacing with your component css.

. complicated-and-specic-name_body {   
   background: blue; 
}

But there is always a way to override in the site where it is used. Only with iframe we can achieve this independance of component.

With phantom DOM, we can as the DOM inside the component, in a similar way than the iframe DOM, is not accessible and targetable by css rules from the exterior.

The problem is the phantom DOM implementation is not yet ready. So in angular 2 they found a system to by pass this (with attributes component name space) and be able ot switch to full phantom DOM support when ready.

With this improvement the 3 part of a web components - css, html and js - are packagable in a convenient way. Component by component and without needing to include a full library where 80% of elements are not useful for you.

Binding

  • the syntax has changed

  • the 2 way bindings is no more the default

  • Top > bottom binding is the default : the binding propagate to component and sub-components

  • To make bottom > top updates, you need to use a event system

Observable on top of promise

Practically at first it could be as simple as replacing the then of promises by the subscribe of observable. But as you get more familiar with observables, you can do more.

Debugging

Though it does not always display all the public properties of the components classes. It is possible to type $a to debug in the console the component available properties. Though I did not find yet the equivalent of $scope.mydata in angular 1 : a quick way to output available data directly from the element tab of chrome debugger;

It seems that is is not more necessary to write $log.debug as the standard console.log seems enough. How to prevent console logs to display in prod? Do not know yet.

Zone.js

Events

Observable are a new type of async object, like promise but with much more possibilities. The doc of observables is available here : .

The debug tools are not the same. I've not finished to discovered the possibilities. But I've found a chrome extension that seem the defacto standard for viewing components hierarchy and properties. It display very nicely the dependencies, the components nesting.

https://www.typescriptlang.org
reactivex.io
Augury