We only need to install angular cli once.
$ npm install @angular/cli -g
Command to create angular base with scss and rounting:
$ ng new ng5 --style=scss --routing
$ cd ng5
$ ng s # or: ng server$ ng g c home # Generate Component home$ ng g c about # Generate Component about- Interpolation :
value="{{btnText}}" - Property Binding :
[value]="btnText" - Event Binding :
(click)="addItem()"- Add function to
home.component.ts:addItem() { this.goals.push(this.goalText); this.goalText = ''; this.itemCount = this.goals.length; }
- Add function to
In order to use ng-model we have to install @angular/forms
- Edit app.module.ts.
- Add import
import {FormsModule} from '@angular/forms';
- Add to imports array
FormsModule
- Add import
- Two way databinding html attribute :
- square brackets with parentheses inside
[(ngModel)]="goalText"
- square brackets with parentheses inside
- How to render array :
<p class="life-container" *ngFor="let goal of goals"> {{goal}} </p>
- Install @angular/animations :
$ npm install @angular/animations@latest --save
- Setup app.modules.ts :
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; - Import animations on
home.component.ts:import {trigger, style, transition, animate, keyframes, stagger} from '@angular/animations';
- Setup app.modules.ts :
Add :
import { HomeComponent } from './home/home.component'
import { AboutComponent } from './about/about.component'
const routes: Routes = [
{ path:'', component: HomeComponent },
{ path:'about/:id', component: AboutComponent }
];Change Html to :
<ul>
<li><a routerLink="">Home</a></li>
<li><a routerLink="about/48">About</a></li>
</ul>
<router-outlet></router-outlet>Add:
import { ActivatedRoute, Router } from '@angular/router';
...
...
constructor(private route: ActivatedRoute,private router: Router)
{
// this.route.params.subscribe(res=>console.log(res.id));
}
sendMeHome()
{
this.router.navigate(['']);
}Add:
<a href="javascript:;" (click)="sendMeHome()">
<strong>take me back</strong>
</a>$ ng g s dataChanges:
source/src/app/about/about.component.html
source/src/app/about/about.component.ts
source/src/app/app.module.ts
source/src/app/data.service.ts
source/src/app/home/home.component.ts
Generate distribution:
$ ng build --prodDeploy:
$ ng build --prodDeployment CLI
$ npm i -g angular-cli-ghpages