0.0.1 • Published 7 years ago

contenta-angular-service v0.0.1

Weekly downloads
3
License
-
Repository
-
Last release
7 years ago

Contenta CMS Angular Service

Shared services for the example Angular consumers.

Installation

To install this library, run:

npm install contenta-angular-service --save

JSON API service

For consumers using JSON API, a service and models are provided to simplify how requests are made to Contenta.

Usage

First, add the ContentaServiceModule to your app module imports:

import { ContentaServiceModule } from 'contenta-angular-service';

@NgModule({
  imports: [
    BrowserModule,
    ContentaServiceModule
  ],
  declarations: [
    AppComponent
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Then in your component, include ContentaDatastore as a provider and define the base URL to your JSON API endpoint.

import { ContentaDatastore } from 'contenta-angular-service';
import { BASE_URL } from 'contenta-angular-service';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [
    ContentaDatastore,
    { provide: BASE_URL, useValue: 'http://localhost/api/' }
  ]
})
export class HomePage {

  constructor(private datastore: ContentaDatastore) {}

}

Once you have the ContentaDatastore instance, you can query Contenta data by referencing the models you need. Here's an example of a simple query:

import { Recipe } from 'contenta-angular-service';

let query = this.datastore.query(Recipe, {
  include: 'image,category,tags'
});
query.subscribe(
  (recipes: Recipe[]) => {
    // I can access recipe.image now!
  }
}

ContentaDatastore extends angular2-jsonapi, which provides all of the logic regarding requests. Please consult the documentation there for anything lacking here.

Development

To build this project, run:

npm run build.

0.0.1

7 years ago

0.0.0

7 years ago