This project was generated with Angular CLI version 7.3.8.
-
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
-
Install Kentico Cloud JavaScript SDK
npm install --save rxjs kentico-cloud-delivery
-
Extend App component code (final state)
-
Add required imports
import { Component, OnInit } from '@angular/core'; import { DeliveryClient, IDeliveryClient ContentItem } from 'kentico-cloud-delivery';
-
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 = []; }
-
Load data from Kentico Cloud and pass them to the
articles
property onngOnInit
method.ngOnInit(): void { this.client.items() .type('article') .getPromise() .then(result => { console.log(result.items); this.articles = result.items; this.loaded = true; }); }
-
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>
-
-
Run the app
npm start
Hurray! Kentico Cloud ❤️ Angular!
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.
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
.
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.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.