<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Angular_2_Hours</id>
	<title>Angular 2 Hours - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Angular_2_Hours"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Angular_2_Hours&amp;action=history"/>
	<updated>2026-04-21T08:50:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Angular_2_Hours&amp;diff=63228&amp;oldid=prev</id>
		<title>Wanghao at 19:05, 31 October 2017</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Angular_2_Hours&amp;diff=63228&amp;oldid=prev"/>
		<updated>2017-10-31T19:05:50Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:private]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;slideshow style=&amp;quot;nobleprog&amp;quot; headingmark=&amp;quot;⌘&amp;quot; incmark=&amp;quot;…&amp;quot; scaled=&amp;quot;true&amp;quot; font=&amp;quot;Trebuchet MS&amp;quot; &amp;gt;&lt;br /&gt;
;title: Anuglar Demo&lt;br /&gt;
;author: Hao WANG&lt;br /&gt;
&amp;lt;/slideshow&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Angular(4) ⌘==&lt;br /&gt;
*https://angular.io&lt;br /&gt;
** New Features&lt;br /&gt;
** Binding&lt;br /&gt;
** Directives, Validation, Pipes&lt;br /&gt;
** Data Flow&lt;br /&gt;
** State Management&lt;br /&gt;
&lt;br /&gt;
== New Features ⌘==&lt;br /&gt;
* Ahead-Of-Time(AOT) compiler improvements (60% on component) (Used by Angular-CLI)&lt;br /&gt;
* Move animation out of the @angular/core package into its own package&lt;br /&gt;
* Angular Universal (server-side rendering) part of the core now&lt;br /&gt;
* TypeScript 2.1/2.2 compatible now, has better type checking&lt;br /&gt;
&lt;br /&gt;
== Syntax Improvements - ngIf, email ⌘==&lt;br /&gt;
* ngIf.. else.. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
&amp;lt;div *ngIf=&amp;quot;machines.length &amp;gt; 0; else empty&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h2&amp;gt;Machines&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;ng-template #empty&amp;gt;&lt;br /&gt;
  &amp;lt;h2&amp;gt;No machines&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;/ng-template&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* new validator: email&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot; line highlight=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
// old way &lt;br /&gt;
&amp;lt;form #frm=&amp;quot;ngForm&amp;quot;&amp;gt;  &lt;br /&gt;
&amp;lt;label&amp;gt;Email&amp;lt;/label&amp;gt;  &lt;br /&gt;
        &amp;lt;input  &lt;br /&gt;
            type=&amp;quot;email&amp;quot;  &lt;br /&gt;
            ngModel  &lt;br /&gt;
            name=&amp;quot;email&amp;quot;  &lt;br /&gt;
            required  &lt;br /&gt;
            style=&amp;quot;width:300px&amp;quot;  &lt;br /&gt;
            pattern=&amp;quot;^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$&amp;quot;/&amp;gt;  &lt;br /&gt;
            &amp;lt;button [disabled]=!frm.valid&amp;gt;Submit&amp;lt;/button&amp;gt;  &lt;br /&gt;
&amp;lt;/form&amp;gt; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot; line highlight=&amp;quot;10&amp;quot;&amp;gt;&lt;br /&gt;
// new way &lt;br /&gt;
&amp;lt;form #frm=&amp;quot;ngForm&amp;quot;&amp;gt;  &lt;br /&gt;
&amp;lt;label&amp;gt;Email&amp;lt;/label&amp;gt;  &lt;br /&gt;
        &amp;lt;input  &lt;br /&gt;
            type=&amp;quot;email&amp;quot;  &lt;br /&gt;
            ngModel  &lt;br /&gt;
            name=&amp;quot;email&amp;quot;  &lt;br /&gt;
            required  &lt;br /&gt;
            style=&amp;quot;width:300px&amp;quot;  &lt;br /&gt;
            email/&amp;gt;  &lt;br /&gt;
            &amp;lt;button [disabled]=!frm.valid&amp;gt;Submit&amp;lt;/button&amp;gt;  &lt;br /&gt;
&amp;lt;/form&amp;gt;  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prepare ⌘==&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
apt-get install nodejs&lt;br /&gt;
apt-get install npm&lt;br /&gt;
apt-get install nodejs-legacy&lt;br /&gt;
node -v&lt;br /&gt;
npm -v&lt;br /&gt;
npm install -g n&lt;br /&gt;
n&lt;br /&gt;
npm install -g @angular/cli&lt;br /&gt;
ng --version&lt;br /&gt;
add-apt-repository ppa:webupd8team/sublime-text-3&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get install sublime-text-installer&lt;br /&gt;
subl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
== Prepare: FormsModule ⌘==&lt;br /&gt;
* Because we want to develop template-driven forms so we import FormsModule&lt;br /&gt;
* To develop Model-driven forms, you can import ReactiveFormsModule as another approach&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot;&amp;gt;&lt;br /&gt;
//app.module.ts&lt;br /&gt;
import { FormsModule } from &amp;#039;@angular/forms&amp;#039;;&lt;br /&gt;
..&lt;br /&gt;
  imports: [&lt;br /&gt;
    BrowserModule,&lt;br /&gt;
    FormsModule&lt;br /&gt;
..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prepare: Create Demo Page ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
  ng g component demo-page&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;row&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;col-md-2&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;ul class=&amp;quot;nav nav-pills nav-stacked&amp;quot;&amp;gt;&lt;br /&gt;
		  &amp;lt;li class=&amp;quot;active&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;topic 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
		  &amp;lt;li&amp;gt;topic 2&amp;lt;/li&amp;gt;&lt;br /&gt;
		  &amp;lt;li&amp;gt;topic 3&amp;lt;/li&amp;gt;&lt;br /&gt;
		&amp;lt;/ul&amp;gt;&lt;br /&gt;
	&amp;lt;/div&amp;gt;&lt;br /&gt;
	&amp;lt;div class=&amp;quot;col-md-10&amp;quot;&amp;gt;&lt;br /&gt;
	       topic detail&lt;br /&gt;
	&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prepare: Topics ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot;&amp;gt;&lt;br /&gt;
topics : string[] = [&amp;quot;Validation&amp;quot;, &amp;quot;Pipe&amp;quot;, &amp;quot;Data Flow&amp;quot;, &amp;quot;State&amp;quot;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prepare: Create playground ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
  ng g component playground&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prepare: playground template ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div [ngSwitch]=&amp;quot;topicName&amp;quot; class=&amp;quot;container&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;ng-container *ngSwitchCase=&amp;quot;&amp;#039;Validation&amp;#039;&amp;quot;&amp;gt;&lt;br /&gt;
	Validation..&lt;br /&gt;
	&amp;lt;/ng-container&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;ng-container *ngSwitchCase=&amp;quot;&amp;#039;Data Flow&amp;#039;&amp;quot;&amp;gt;&lt;br /&gt;
	Data Flow..&lt;br /&gt;
	&amp;lt;/ng-container&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;ng-container *ngSwitchCase=&amp;quot;&amp;#039;State Management&amp;#039;&amp;quot;&amp;gt;&lt;br /&gt;
	State Management..&lt;br /&gt;
	&amp;lt;/ng-container&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Bindings ⌘==&lt;br /&gt;
* https://angular.io/guide/template-syntax#binding-targets&lt;br /&gt;
* property - one way in&lt;br /&gt;
* event - one way out&lt;br /&gt;
* two way &lt;br /&gt;
* attribute&lt;br /&gt;
* class&lt;br /&gt;
* style&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot;&amp;gt;&lt;br /&gt;
//app.component.ts&lt;br /&gt;
&amp;lt;hero-detail [hero]=&amp;quot;currentHero&amp;quot; (deleteRequest)=&amp;quot;deleteHero()&amp;quot;&amp;gt;&amp;lt;/hero-detail&amp;gt;&lt;br /&gt;
// Data: currentHero ---- down ---&amp;gt; target element&lt;br /&gt;
// Event: deleteRequest ---- up ----&amp;gt; parent component ( app component in this case )&lt;br /&gt;
// this is also how the data flows in and out&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pipe Example ⌘==&lt;br /&gt;
* DecimalPipe &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot;&amp;gt;&lt;br /&gt;
{{ xxxxx | number: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits} }}&lt;br /&gt;
// defaults: 1.0-3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Directive ⌘==&lt;br /&gt;
About directive, all these are true:&lt;br /&gt;
* An Angular class, it adds behavior to HTML element or its attribute&lt;br /&gt;
* often refer to the HTML element or its attribute as the directive like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot; inline&amp;gt; &amp;lt;my-component&amp;gt;, &amp;lt;div [ngClass].., &amp;lt;div [ngStyle]..&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* When Angular finds a directive in an HTML template, it creates the matching directive class instance and gives the instance control over that portion of the browser DOM.&lt;br /&gt;
* You can invent custom HTML markup (for example, &amp;lt;my-directive&amp;gt;) to associate with your custom directives, a component for example.&lt;br /&gt;
&lt;br /&gt;
== Directive most of the time can fall into 3 categories ⌘==&lt;br /&gt;
** Components - technically a directive with a template.&lt;br /&gt;
** Attribute directives - appear as attribute on html elements to decorate and add behavior to elements&lt;br /&gt;
** Structural directives - manipulating html layout and elements.&lt;br /&gt;
&lt;br /&gt;
== Validation 1 ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;js&amp;quot;&amp;gt;&lt;br /&gt;
hero: Hero = new Hero();&lt;br /&gt;
powers = [&amp;#039;Really Smart&amp;#039;, &amp;#039;Super Flexible&amp;#039;, &amp;#039;Weather Changer&amp;#039;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;row&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;col-sm-4 col-sm-offset-4&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;form #heroForm=&amp;quot;ngForm&amp;quot; (ngSubmit)=&amp;quot;onSubmit()&amp;quot;&amp;gt;&lt;br /&gt;
          &lt;br /&gt;
          &amp;lt;button type=&amp;quot;submit&amp;quot; class=&amp;quot;btn btn-default&amp;quot;&lt;br /&gt;
               [disabled]=&amp;quot;!heroForm.form.valid&amp;quot;&amp;gt;Submit&amp;lt;/button&amp;gt;&lt;br /&gt;
      &amp;lt;/form&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
== Validation 2 ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;form-group&amp;quot;&amp;gt;&lt;br /&gt;
                    &lt;br /&gt;
            &amp;lt;label for=&amp;quot;name&amp;quot;&amp;gt;Name&amp;lt;/label&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot; class=&amp;quot;form-control&amp;quot;&lt;br /&gt;
                   required minlength=&amp;quot;4&amp;quot; maxlength=&amp;quot;24&amp;quot;&lt;br /&gt;
                   name=&amp;quot;name&amp;quot; [(ngModel)]=&amp;quot;hero.name&amp;quot;&lt;br /&gt;
                   #name=&amp;quot;ngModel&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;div *ngIf=&amp;quot;name.errors &amp;amp;&amp;amp; (name.dirty || name.touched)&amp;quot;&lt;br /&gt;
                 class=&amp;quot;alert alert-danger&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;div [hidden]=&amp;quot;!name.errors.required&amp;quot;&amp;gt;&lt;br /&gt;
                  Name is required&lt;br /&gt;
                &amp;lt;/div&amp;gt;&lt;br /&gt;
                &amp;lt;div [hidden]=&amp;quot;!name.errors.minlength&amp;quot;&amp;gt;&lt;br /&gt;
                  Name must be at least 4 characters long.&lt;br /&gt;
                &amp;lt;/div&amp;gt;&lt;br /&gt;
                &amp;lt;div [hidden]=&amp;quot;!name.errors.maxlength&amp;quot;&amp;gt;&lt;br /&gt;
                  Name cannot be more than 24 characters long.&lt;br /&gt;
                &amp;lt;/div&amp;gt;&lt;br /&gt;
            &amp;lt;/div&amp;gt;&lt;br /&gt;
          &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
== Validation 3 ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;div class=&amp;quot;form-group&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;label for=&amp;quot;email&amp;quot;&amp;gt;Hero Email&amp;lt;/label&amp;gt;&lt;br /&gt;
            &lt;br /&gt;
            &amp;lt;input type=&amp;quot;email&amp;quot; id=&amp;quot;email&amp;quot; class=&amp;quot;form-control&amp;quot;&lt;br /&gt;
                   required email&lt;br /&gt;
                   name=&amp;quot;email&amp;quot; [(ngModel)]=&amp;quot;hero.email&amp;quot;&lt;br /&gt;
                   #email=&amp;quot;ngModel&amp;quot; &amp;gt;&lt;br /&gt;
     &lt;br /&gt;
            &amp;lt;div *ngIf=&amp;quot;email.errors &amp;amp;&amp;amp; email.touched&amp;quot; class=&amp;quot;alert alert-danger&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;div [hidden]=&amp;quot;!email.errors.required&amp;quot;&amp;gt;Email is required&amp;lt;/div&amp;gt;&lt;br /&gt;
              &amp;lt;div [hidden]=&amp;quot;email.errors.required || !email.errors.email&amp;quot;&amp;gt;Email is not valid&amp;lt;/div&amp;gt;&lt;br /&gt;
            &amp;lt;/div&amp;gt;&lt;br /&gt;
          &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
== Validation 4 ⌘==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
           &amp;lt;div class=&amp;quot;form-group&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;label for=&amp;quot;power&amp;quot;&amp;gt;Hero Power&amp;lt;/label&amp;gt;&lt;br /&gt;
            &amp;lt;select id=&amp;quot;power&amp;quot; class=&amp;quot;form-control&amp;quot;&lt;br /&gt;
                    name=&amp;quot;power&amp;quot;&lt;br /&gt;
                    [(ngModel)]=&amp;quot;hero.power&amp;quot; required&lt;br /&gt;
                    #power=&amp;quot;ngModel&amp;quot; &amp;gt;&lt;br /&gt;
              &amp;lt;option *ngFor=&amp;quot;let p of powers&amp;quot; [value]=&amp;quot;p&amp;quot;&amp;gt;{{p}}&amp;lt;/option&amp;gt;&lt;br /&gt;
            &amp;lt;/select&amp;gt;&lt;br /&gt;
     &lt;br /&gt;
            &amp;lt;div *ngIf=&amp;quot;power.errors &amp;amp;&amp;amp; power.touched&amp;quot; class=&amp;quot;alert alert-danger&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;div [hidden]=&amp;quot;!power.errors.required&amp;quot;&amp;gt;Power is required&amp;lt;/div&amp;gt;&lt;br /&gt;
            &amp;lt;/div&amp;gt;&lt;br /&gt;
          &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data Flow 1 ⌘==&lt;br /&gt;
[[File:adau.png]]&lt;br /&gt;
&lt;br /&gt;
== Data Flow 2 ⌘==&lt;br /&gt;
* create 5 component, namely comp1, comp2, comp3, comp4, comp5&lt;br /&gt;
* comp1 contains 3 and 4&lt;br /&gt;
* comp2 contains 5&lt;br /&gt;
* Data flow rules:(data is presented as input element)&lt;br /&gt;
** app data flow to comp1&lt;br /&gt;
** comp1 data flow within itself &lt;br /&gt;
** comp5 flow to app&lt;br /&gt;
** exercise. comp5 flow to comp3&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
.comp1,&lt;br /&gt;
.comp2{&lt;br /&gt;
	width:400px;&lt;br /&gt;
	height:auto;&lt;br /&gt;
}&lt;br /&gt;
.comp1 {background-color: lightblue;}&lt;br /&gt;
.comp2 {background-color: yellow;}&lt;br /&gt;
.comp3,&lt;br /&gt;
.comp4,&lt;br /&gt;
.comp5{&lt;br /&gt;
	width:200px;&lt;br /&gt;
	height:200px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== State Management 1 ⌘==&lt;br /&gt;
[[File:redux-article-3-03.svg]]&lt;br /&gt;
&lt;br /&gt;
== State Management 2 ⌘==&lt;br /&gt;
&lt;br /&gt;
https://github.com/ngrx/store&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
npm install @ngrx/core @ngrx/store --save&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wanghao</name></author>
	</entry>
</feed>