Getting started with
Angular CLI
Sasha Vinčić
Digital Viking
servitant.se
ngVikings
The Northernmost Angular Conference
February 11-12, Copenhagen
ngvikings.org
Angular CLI
A command line interface for Angular
Why Angular CLI?
• Easy to create
• Works 

right out of the box
• Follows best practices
Photocred: Malmö Eastern egg, Susanne Nilsson, CC BY
Angular CLI
Lets start
• ng new

Create a new project
• ng serve

Start it
Photocred: Double powered start, flickr.com/brandsvig, CC BY
Lets test
• ng test

Runs test suite
• ng e2e

Runs end to end tests
Photocred: Lego People, Peter Dutton, CC BY
ng generate
• ng g component main-header

MainHeaderComponent
• ng g service login 

LoginService
• ng g module shared

src/app/shared
Photocred: Wheel of Malmö, Frank Scmidt, CC BY
Components, Services and Module
ng generate
• ng g interface shared/city

app/shared/city
• ng g class shared/models/user

app/shared/models/user
Photocred: Non Human Device, Boris Chimp, CC BY
Interfaces, Classes
3rd Party lib installation
npm install @ng-bootstrap/ng-bootstrap
import {NgbModule} from ‘@ng-bootstrap/ng-bootstrap';

@NgModule({
declarations: [AppComponent, ...],
imports: [NgbModule.forRoot(), ...],
bootstrap: [AppComponent]
})
export class AppModule {
}
Photocred: Enlightenment, Camilla Nilsson, CC BY
Global lib installation
npm install bootstrap@4.0.0-alpha.5
“styles”: [

“../node_modules/bootstrap/dist/css/bootstrap.css

]
Photocred: Enlightenment, Camilla Nilsson, CC BY
Under the hood
Angular 2.1.0
Webpack 2.1.0-beta
TypeScript 2.0.3
karma, less, sass, tslint
Photocred: Pop the hood, Jesper Yu, CC BY
new projects
• ng new —prefix=ngmalmo
• ng new —style=sass
• ng new —style=less
• ng new —skip-git=true —skip-npm=true

Photocred: Stamps, Michelle, CC BY
More features
• ng init —mobile true
• ng g route
• ng completion 1>> ~/.bashrc 2>>&1
• ng github-pages:deploy
Photocred: Toolbox, Florian Richter, CC BY
some disabled
building
ng build -prod

ng build -t production

ng build —target=production 

Build for production
Photocred: Ikea, Junky Pamies Alcubilila CC BY
Faster
ng build —aot=true

Faster & “smaller”
Photocred: Mellisuga helenae, Ekaterina Chernetsova CC BY
Proxy
proxy.conf.json

{

“/api”: {

“target”: “http://localhost:3000”,

“secure”: false

}

}
Photocred:réfraction champêtre, Hervé Laville, CC BY
AngularJS Malmö
Meetup
Go now to www.menti.com and use the code 80 19 01
Photocred: In the city, Maria Eklind, CC BY

Getting started with Angular CLI

  • 1.
  • 2.
  • 3.
  • 4.
    ngVikings The Northernmost AngularConference February 11-12, Copenhagen ngvikings.org
  • 5.
    Angular CLI A commandline interface for Angular
  • 6.
    Why Angular CLI? •Easy to create • Works 
 right out of the box • Follows best practices Photocred: Malmö Eastern egg, Susanne Nilsson, CC BY
  • 7.
  • 8.
    Lets start • ngnew
 Create a new project • ng serve
 Start it Photocred: Double powered start, flickr.com/brandsvig, CC BY
  • 9.
    Lets test • ngtest
 Runs test suite • ng e2e
 Runs end to end tests Photocred: Lego People, Peter Dutton, CC BY
  • 10.
    ng generate • ngg component main-header
 MainHeaderComponent • ng g service login 
 LoginService • ng g module shared
 src/app/shared Photocred: Wheel of Malmö, Frank Scmidt, CC BY Components, Services and Module
  • 11.
    ng generate • ngg interface shared/city
 app/shared/city • ng g class shared/models/user
 app/shared/models/user Photocred: Non Human Device, Boris Chimp, CC BY Interfaces, Classes
  • 12.
    3rd Party libinstallation npm install @ng-bootstrap/ng-bootstrap import {NgbModule} from ‘@ng-bootstrap/ng-bootstrap';
 @NgModule({ declarations: [AppComponent, ...], imports: [NgbModule.forRoot(), ...], bootstrap: [AppComponent] }) export class AppModule { } Photocred: Enlightenment, Camilla Nilsson, CC BY
  • 13.
    Global lib installation npminstall bootstrap@4.0.0-alpha.5 “styles”: [
 “../node_modules/bootstrap/dist/css/bootstrap.css
 ] Photocred: Enlightenment, Camilla Nilsson, CC BY
  • 14.
    Under the hood Angular2.1.0 Webpack 2.1.0-beta TypeScript 2.0.3 karma, less, sass, tslint Photocred: Pop the hood, Jesper Yu, CC BY
  • 15.
    new projects • ngnew —prefix=ngmalmo • ng new —style=sass • ng new —style=less • ng new —skip-git=true —skip-npm=true
 Photocred: Stamps, Michelle, CC BY
  • 16.
    More features • nginit —mobile true • ng g route • ng completion 1>> ~/.bashrc 2>>&1 • ng github-pages:deploy Photocred: Toolbox, Florian Richter, CC BY some disabled
  • 17.
    building ng build -prod
 ngbuild -t production
 ng build —target=production 
 Build for production Photocred: Ikea, Junky Pamies Alcubilila CC BY
  • 18.
    Faster ng build —aot=true
 Faster& “smaller” Photocred: Mellisuga helenae, Ekaterina Chernetsova CC BY
  • 19.
    Proxy proxy.conf.json
 {
 “/api”: {
 “target”: “http://localhost:3000”,
 “secure”:false
 }
 } Photocred:réfraction champêtre, Hervé Laville, CC BY
  • 20.
    AngularJS Malmö Meetup Go nowto www.menti.com and use the code 80 19 01 Photocred: In the city, Maria Eklind, CC BY