Getting started with Angular 2Dynamically add components using ViewContainerRef.createComponentPipesRouting (3.0.0+)Http InterceptorDirectivesInstalling 3rd party plugins with [email protected]Testing an Angular 2 AppRoutingOptimizing rendering using ChangeDetectionStrategyLifecycle HooksDirectives & components : @Input @OutputAngular RXJS Subjects and Observables with API requestsZone.jsServices and Dependency InjectionAngular 2 Forms UpdateDetecting resize eventsBootstrap Empty module in angular 2Advanced Component ExamplesBypassing Sanitizing for trusted valuesAngular2 Custom ValidationsAngular 2 Data Driven FormsAngular - ForLoopFeature ModulesAngular2 In Memory Web APIAhead-of-time (AOT) compilation with Angular 2Debugging Angular2 typescript application using Visual Studio CodeCRUD in Angular2 with Restful APIComponent interactionsUse native webcomponents in Angular 2Lazy loading a moduleUpdate typingsMocking @ngrx/StoreHow to use ngforngrxAnimationCommonly built-in directives and servicesHow to Use ngifTesting ngModelCreate an Angular 2+ NPM packageAngular2 CanActivateAngular 2 - ProtractorExample for routes such as /route/subroute for static urlsAngular2 Input() output()Page titleunit testingAngular-cliOrderBy PipeAngular2 AnimationsAngular 2 Change detection and manual triggeringAngular2 DatabindingBrute Force UpgradingEventEmitter ServiceAngular2 provide external data to App before bootstrapUsing third party libraries like jQuery in Angular 2Component interactionsAttribute directives to affect the value of properties on the host node by using the @HostBinding decorator.TemplatesConfiguring ASP.net Core application to work with Angular 2 and TypeScriptAngular2 using webpackAngular material designDropzone in Angular2custom ngx-bootstrap datepicker + inputangular reduxCreating an Angular npm libraryBarrelangular-cli test coverageService WorkerComponentsModules

Angular-cli

Other topics

Create empty Angular2 application with angular-cli


Requirements:


Run the following commands with cmd from new directory folder:

  1. npm install -g @angular/cli or yarn global add @angular/cli
  2. ng new PROJECT_NAME
  3. cd PROJECT_NAME
  4. ng serve

Open your browser at localhost:4200

Generating Components, Directives, Pipes and Services

just use your cmd: You can use the ng generate (or just ng g) command to generate Angular components:

  • Component: ng g component my-new-component
  • Directive: ng g directive my-new-directive
  • Pipe: ng g pipe my-new-pipe
  • Service: ng g service my-new-service
  • Class: ng g class my-new-classt
  • Interface: ng g interface my-new-interface
  • Enum: ng g enum my-new-enum
  • Module: ng g module my-module

Adding 3rd party libs

In angular-cli.json you can change the app configuration.

If you want to add ng2-bootstrap for example:

  1. npm install ng2-bootstrap --save or yarn add ng2-bootstrap

  2. In angular-cli.json just add the path of the bootstrap at node-modules.

    "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/bootstrap/dist/js/bootstrap.js"
     ]
    

build with angular-cli

In angular-cli.json at outDir key you can define your build directory;

these are equivalent

ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod

and so are these

ng build --target=development --environment=dev
ng build --dev --e=dev
ng build --dev
ng build

When building you can modify base tag () in your index.html with --base-href your-url option.

Sets base tag href to /myUrl/ in your index.html

ng build --base-href /myUrl/
ng build --bh /myUrl/

New project with scss/sass as stylesheet

The default style files generated and compiled by @angular/cli are css.

If you want to use scss instead, generate your project with:

ng new project_name --style=scss

If you want to use sass, generate your project with:

ng new project_name --style=sass

Set yarn as default package manager for @angular/cli

Yarn is an alternative for npm, the default package manager on @angular/cli. If you want to use yarn as package manager for @angular/cli follow this steps:

Requirements

To set yarn as @angular/cli package manager:

ng set --global packageManager=yarn

To set back npm as @angular/cli package manager:

ng set --global packageManager=npm

Contributors

Topic Id: 8956

Example Ids: 27869,27870,27871,27872,32655,32656

This site is not affiliated with any of the contributors.