Tips and Tricks in a world of Mix

Archive for the ‘angular2’ Category

Init type instance in Typescript 2.1 automatically – loved it !

So simple and elegant :

Found in this post


Typescript 2.1 introduces Mapped Types and provides Partial<T>, which allows you to do this….

class Person {
    public name: string = "default"
    public address: string = "default"
    public age: number = 0;

    public constructor(init?:Partial<Person>) {
        Object.assign(this, init);

let persons = [
    new Person(),
    new Person({}),
    new Person({name:"John"}),
    new Person({address:"Earth"}),    
    new Person({age:20, address:"Earth", name:"John"}),

Angular 2 MeshRehovot EYAL VARDI 03.02.2017

Angular 2 MeshRehovot eYAL vARDI 03.02.2017 added to browsers and deleteing the declerative programming

the components will be built in browser

Chrome 58 תומך ב אסמבלי
מגיעים למליון שורות קוד וזה כבד מדיי

Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web pages and web apps. Custom components and widgets build on the Web Component standards, will work across modern browsers, and can be used with any JavaScript library or framework that works with HTML.

Web components are based on existing web standards. Features to support web components are currently being added to the HTML and DOM specs, letting web developers easily extend HTML with new elements with encapsulated styling and custom behavior. – has a demo of running an extra large code through
– we can run it only using the chrome canary version. This is an experimental demo of Angry Bots, a Unity game which has been ported to WebAssembly.

You can see a screen record of the chrome canary browser. can get binary code and even run c++

.net is dead in a long run. That is a tendency which we can see for a long time now.

Even the new items of .net team are directed for using the js as a base.

For instance in a TechSummit at a lecture reviewing new SharePoint the Microsoft representatives were only talking about how to build web-parts with Angular and React. You can read more at my post about that event here – SharePoint with all the new toys. It’s beyond the theme of this post , but it vividly shows the direction of the high-tech industry overall.

The future is in fullstack js – including node.js

Examples are at – paypal, netflix, linkedin – moving to js. – quick bootstrap option .

Better Perceived Performance

First time users of your application will instantly see a server rendered view which greatly improves perceived performance and the overall user experience. According to research at Google, the difference of just 200 milliseconds in page load performance has an impact on user behavior.

Optimized for Search Engines

Although Googlebot crawls and renders most dynamic sites, many search engines expect plain HTML. Server-side pre-rendering is a reliable, flexible and efficient way to ensure that all search engines can access your content.

ng-metadata – a library from angular1 to angular2

ng-metadata is a great solution for people who want to gradually update an existing ng1 codebase to TypeScript/ES2015 using Angular 2 conventions and styles that runs today on Angular 1.4+.


js with typescript – getting the experience of java and .net
java is big data so it will survive more time.
java has ide for free , but has more solutions and frameworks.

.net – updated the syntex each two years but has just .core, webapi and mvc solutions.

Angular4 is released.  You can get it fromgithub
The changes in Angular4 will be in eco system and not in programming syntax.
It should enable us to upload 1 milion rows code.

Tooks core-js with pollyfills for es5 but added es6.
Libraries – the ones to use for future

Modular standard library for JavaScript. Includes polyfills for ECMAScript 5, ECMAScript 6: promises, symbols, collections, iterators, typed arrays, ECMAScript 7+ proposals, setImmediate, etc. Some additional features such as dictionaries or extended partial application. You can require only needed features or use it without global namespace pollution.

RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code. This project is a rewrite of Reactive-Extensions/RxJS with better performance, better modularity, better debuggable call stacks, while staying mostly backwards compatible, with some breaking changes that reduce the API surface.

A Zone is an execution context that persists across async tasks. You can think of it as thread-local storage for JavaScript VMs.
Framework – you just write a part of code and someone else activates it
Router Http Compiler Platform
Custom tag –

Injector – service – business logic
Directive – metadata – for template

MOdule – is container connecting all together


Compiler (JIT vs AOT)

JIT 1.1mg of compiler –
SOurce COde –> RUntime: (template +parser+ abstract syntax tree)

at the aot
(template +parser+ abstract syntax tree) is created on the server from before the runtime at the client
so it’s very quick and the outcome is that the comipler itself is smaller 100kb instead of JIT compiler of 1.1MB


webpack.js – for production
system.src.js – for debug , quicker

shim is a pollifill for older browsers

point of entry System.ipmort async after rendering the dom – setting of the first main.js

platformBrowserDynamic – can be changed for nativescript for android ios , and more options of platforms.

Why components are also in @NgModule declarations
needed for compiler

the compiler takes the templates and translates it
inside the appmodule in sources in the chrome browser the rendered code is not working on dom but goes through th e self.renderer


Offline compile (template +parser+ abstract syntax tree)
A tree shaker walks the dependency graph top to bottom and shakes out unused code.
Minification – removes all unnecessary chars without changing functionality.

Typescript compiles the code from ts to js.Can define tsconfig.js comiplerOptions:”es5″
For now compiles to es5 for browsers to be compatible. After will just change the es5 to es6. Can see the compatibility of the browsers in a www
The compiler compiles the templates of html to js.

var p=Injector.resolveAndCReate([A,B,C])
var c1 = p.resolveAndCReateChild([A,B])
var c2 = c1.resolveAndCReateChild([A]) –creates new

Can approach the fathers through the declaration.

Each component has it’s own injector.
Will go up in hierarchy untill gets the needed injected object, if null throws error if not @Optional.


First off all write business logic
WOrk with getter
get tasks(){
return this.todoService.tasks;
not this.tasks = this.todoService.tasks;
in component code behind


for deleteing the item



Don’t use Event Emmitter
Always through a service.
If it’s connected to the parent just inject parents services.

Lazy initialization
useclass when you give a provide of the type of the class in the constructor
you can add useclass to direct constructor to init lazy load only when needed.

Template Context

bootstrap defining the most upper module
imports is like using in .net — inner use aloud inside the module
exports is what i am aloud to use in outside the module
index.html is not compiled that s why we set only the css , scripts and entry point – its like the manifest for the app.
providers defined in NgModule is recognized by Application Injector, so no need to add it to imports because it’s already available.

if it’s lazy bounding then it’ll be injected to the Module Injector and not Application.

Core Module – only in App module (like HttpModule,BrowserModule)
Add .Core to Module if it’s core module.

Shared Module – is a module for UI , connected to different features.(Unifying controls of Grids,Controlls – almost always third party + some extentions on your part)

Feature Module –

Protection for COre Module

constructor(@Optional() @SkipSelf() parentModule:CoreModule){
if(parentModule) — meaning there are two of them
{ throw new Error(“CoreModule is already loaded’);

static forRoot(config:UserServiceConfig):ModuleWithProviders{



Model Challenges

Data changes if there are
Timer , Communication or UI Events
Wrapps the events and calls tick at the end to refresh
Angular build a tree of expressions per component
Caclulates the previous expressions to the current each async event and the tick slows

Freq*Qexp = Speed

High Frequency Problem
Disconnect from the tick specific component

find code

On Push Strategy


cd.detach in ctor in method

rx auditTime(500) – each half second – reduces the events
auditTime.threshold(15) – if the prev and curr the same don’t updated

scan – saves state

creates observable

feed.service.ts start works with worker adding callback for update

enables chaining


Ways to reduce ticks

Detach one loaded components
On push – only when getting new data will update
On dirty – adding threshold when to refresh

Don’t use setinterval, only setimeout – Zone run outside angular.




Order of hooks

OnChanges – gets inputs


{{}} interpullation expression returns string
[] expression that can return object or array. it’s a property of dom object of the current tag.
() event on dom
*ngIf *ngFor – it’s like words describing the dom

Component Infrastracture

Renderer — work with jQUery — leave element.nativeELement to able to switch to other clients other than browser

Adding events and binding without them knowing the controls effected.


NgIf uses ViewCOntainerRef – enables acces to dom inner html
bennadel using an item template an html dropdown menu component in angular

using ViewCOntainerRef to inject item for each

Using ContentChild or ContentChildren of type TemplateRef


Creating data template for dropdown


wijmo – webexpress

Tag Cloud

%d bloggers like this: