Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Latest commit

 

History

History
119 lines (82 loc) · 3.12 KB

File metadata and controls

119 lines (82 loc) · 3.12 KB

Kentico Cloud ❤️ Angular

This project was generated with Angular CLI version 7.3.8.

How to achieve this state

  1. Install the Angular cli and generate the bootstrapped application (no Router was included)

    In the target folder

    npm install -g @angular/cli
    ng new kc-angular # say no for router option
    cd kc-angular
    ng serve # in case of testing
  2. Install Kentico Cloud JavaScript SDK

    npm install --save rxjs kentico-cloud-delivery
  3. Extend App component code (final state)

    1. Add required imports

      import { Component, OnInit } from '@angular/core';
      import {
        DeliveryClient,
        IDeliveryClient
        ContentItem
        } from 'kentico-cloud-delivery';
    2. Introduce required properties and set them in constructor

      client: IDeliveryClient;
      articles: ContentItem[];
      loaded: boolean;
      title = 'kc-angular';
      
      constructor() {
        this.client = new DeliveryClient({
          projectId: '975bf280-fd91-488c-994c-2f04416e5ee3' 
          });
        this.loaded = false;
        this.articles = [];
      }
    3. Load data from Kentico Cloud and pass them to the articles property on ngOnInit method.

      ngOnInit(): void {
          this.client.items()
            .type('article')
            .getPromise()
            .then(result => {
              console.log(result.items);
              this.articles = result.items;
              this.loaded = true;
            });
        }
    4. Adjust App component template (final result)

      By adding html section tag

      <section *ngIf="loaded">
        <ul *ngFor="let article of articles">
          <li>{{article.elements.title.value}}</li>
        </ul>
      </section>
  4. Run the app

npm start

Hurray! Kentico Cloud ❤️ Angular!

Angular showcase



Application documentation

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.