Build a Serverless CMS-powered Angular App

Build a Serverless CMS-powered Angular App

How to build a serverless CMS-powered Angular app. Installation. First, you'll get started by installing the Angular cli. Quickly get started. Open the project in your code editor of choice. Add marketing pages...

This tutorial will demonstrate how to build a CMS-powered Angular application that has marketing pages (customer case studies), a blog, and FAQ, all powered via an API. No servers needed!

Installation

First, you’ll get started by installing the Angular CLI.

npm install -g @angular/cli</td>

Set up a new Angular project using Angular CLI. By default, Angular CLI uses CSS styling, so adding the --style=scssflag tells Angular CLI to use SCSS instead:

ng new hello-buttercms-project --style=scss
cd hello-buttercms-project

Install Angular Material and Angular Material related package:

npm install --save @angular/material @angular/cdk
npm install --save @angular/animations

Install ButterCMS. Run this in your command line:

npm install buttercms --save

Butter can also be loaded using a CDN:

<script src="https://cdnjs.buttercms.com/buttercms-1.1.1.min.js"></script>
Quickly Get Started

Open the project in your code editor of choice. Under src/app create a directory called _services.

We create a file called butterCMS.service.js. This allows us to have your API Token in one place and not accidentally alter it.

import * as Butter from 'buttercms';

export const butterService = Butter('b60a008584313ed21803780bc9208557b3b49fbb');

You’ll import this file into any component we want to use ButterCMS.

For a Quickstart, go to src/app/hello-you/hello-you.component.ts and import butterService:

import {butterService} from '../_services';

Inside the HelloYouComponent create methods:

fetchPosts() {
butter.post.list({
page: 1,
page_size: 10
})
.then((res) => {
console.log('Content from ButterCMS')
console.log(res)
})
}

Now call this method when the component is loaded by adding it to the OnInit lifecycle hook:

ngOnInit() {
this.fetchPosts();
}

This API request fetches your blog posts. Your account comes with one example post, which you’ll see in the response.

Next, create another method to retrieve the Homepage Headline Content Field:

fetchHeadline() {
butter.content.retrieve(['homepage_headline'])
.then((res) => {
console.log('Headline from ButterCMS')
console.log(res)
})
}

Add this method to the OnInit lifecycle hook.

ngOnInit() {
this.fetchPosts();
this.fetchHeadline();
}

This API request fetches homepage headline content. You can set up your own custom content fields to manage any kind of content you need.

Add Marketing Pages

Setting up CMS-powered pages is a simple, three-step process:

  1. Define the Page Type
  2. Create a page
  3. Integrate into your application

Define Page

First, create a Page Type to represent your Customer Case Study pages. Next, define the fields you want for your customer case studies. With your Page Type defined, you can now create the first case study page. Specify the name and URL of the page, and then populate the content of the page.

With your page defined, the ButterCMS API will return it in JSON format like this:

{
"data": {
"slug": "acme-co",
"fields": {
"facebook_open_graph_title": "Acme Co loves ButterCMS",
"seo_title": "Acme Co Customer Case Study",
"headline": "Acme Co saved 200% on Anvil costs with ButterCMS",
"testimonial": "<p>We've been able to make anvils faster than ever before! - <em>Chief Anvil Maker</em></p>\r\n<p><img src="https://cdn.buttercms.com/NiA3IIP3Ssurz5eNJ15a" alt="" caption="false" width="249" height="249" /></p>",
"customer_logo": "https://cdn.buttercms.com/c8oSTGcwQDC5I58km5WV",
}
}
}

This guide uses the Angular framework and Angular CLI to generate all our components and package our application.

Let’s get to the code.

Create a New Project

ng new buttercms-project --style=scss
cd buttercms-project
npm install --save @angular/material @angular/cdk
npm install --save @angular/animations
npm install -S buttercms
ng serve

Your localhost:4200 should be ready to serve your Angular page.

Create TypeScript to Export ButterCMS Service

Under src/app, create a directory called _services. Create a file called butterCMS.service.js.

import * as Butter from 'buttercms';
export const butterService = Butter('your_api_token');

Update the Component Routes

These components are generated by Angular CLI using:

ng g component <my-new-component>

Under src/app, create a file called app-routing.module.ts:

import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {CustomerComponent} from './customer/listing/customer.listing.component';
import {FaqComponent} from './faq/faq.component';
import {BlogPostComponent} from './blog-post/listing/blog-post.component';
import {HomeComponent} from './home/home.component';
import {CustomerDetailsComponent} from './customer/details/customer.details.component';
import {BlogPostDetailsComponent} from './blog-post/details/blog-post.details.component';
import {FeedComponent} from './feed/feed.component';
import {HelloYouComponent} from './hello-you/hello-you.component';

const appRoutes: Routes = [
{path: 'customer', component: CustomerComponent},
{path: 'customer/:slug', component: CustomerDetailsComponent},
{path: 'faq', component: FaqComponent},
{path: 'blog', component: BlogPostComponent},
{path: 'blog/:slug', component: BlogPostDetailsComponent},
{path: 'rss', component: FeedComponent},
{path: 'hello-you', component: HelloYouComponent},
{path: 'home', component: HomeComponent},
{path: '**', redirectTo: 'home'}
];

@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}

Set Up the Customers List Page

Under apps/customer type:

ng g component listing

In the file apps/customer/listing/customer.listing.component.ts:

  1. Import butterService
  2. In the OnInit hook, use butterService to get the list of customers
  3. Store results in the pages variable and the markup (HTML) will be updated with the data.
import {Component, OnInit} from '@angular/core';
import {butterService} from '../../_services';

@Component({
selector: 'app-customer',
templateUrl: './customer.listing.component.html',
styleUrls: ['./customer.listing.component.scss']
})

export class CustomerComponent implements OnInit {
public pages: any[];
constructor() { }

ngOnInit() {
butterService.page.list('customer_case_study')
.then((res) => {
this.pages = res.data.data;
});
}
}

Display the results in customer.listing.component.html:

<mat-card>
<mat-card-title class="page-title">Customers</mat-card-title>
<mat-divider></mat-divider>
<mat-card-content class="page-body">
<mat-card *ngFor="let page of pages">
<mat-card-title>
<div class="container">
<a [routerLink]="[page.slug]">
<div fxLayout="row" fxLayout.xs="column"
fxFlex class="content">
<div class="blocks">
<img src="{{page.fields.customer_logo}}" alt="{{page.fields.seotitle}}" height="64"
width="64"/>
</div>
<div class="blocks">
{{page.fields.headline}}
</div>
</div>
</a>
</div>
</mat-card-title>
</mat-card>
</mat-card-content>
<mat-divider></mat-divider>
<mat-card-footer>
<div class="page-footer">
<mat-icon>whatshot</mat-icon>
</div>
</mat-card-footer>
</mat-card>
Set Up the Customer Detail Page

Under apps/customer, type ng g component details.

apps/customer/details/customer.details.component.ts

Create the customer page

  1. Import butterService
  2. In the OnInit hook, use butterService to get the customer page given the slug in the URL path
  3. Store results in a page variable and the markup (HTML) will be updated with the customer data.
import {Component, OnInit} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {ActivatedRoute} from '@angular/router';
import {butterService} from '../../_services';
import {map, take} from 'rxjs/operators';

@Component({
selector: 'app-customer-details',
templateUrl: './customer.details.component.html',
styleUrls: ['./customer.details.component.scss']
})

export class CustomerDetailsComponent implements OnInit {
constructor(protected route: ActivatedRoute) { }

protected slug$: Observable<string>;
public page: any;

ngOnInit() {
this.slug$ = this.route.paramMap
.pipe(
map(params => (params.get('slug')))
);

this.slug$.pipe(
  take(1))
  .subscribe(slug =&gt; {
    butterService.page.retrieve('customer_case_study', slug)
      .then((res) =&gt; {
        this.page = res.data.data;
      }).catch((res) =&gt; {
      console.log(res);
    });
  });

}
}

Display the results in customer.details.component.html.

<mat-card>
<div class="container">
<div fxLayout="column" class="details">
<div class="blocks">
<img src="{{page.fields.customer_logo}}" alt="" height="124" width="124"/>
</div>

  &lt;h1 class="blocks"&gt;
    {{page.fields.headline}}
  &lt;/h1&gt;
  &lt;h3 class="is-size-3"&gt;Testimonials&lt;/h3&gt;
  &lt;div [innerHTML]="page.fields.testimonial"&gt;&lt;/div&gt;
  &lt;div [innerHTML]="page.fields.body"&gt;&lt;/div&gt;
&lt;/div&gt;

</div>
</mat-card>

You can now navigate to the Customer Page via the list of all Customer Pages or directly via the URL.

Add a Knowledge Base

Set up content fields

Let’s suppose you want to add a CMS to a static FAQ page with a title and a list of questions with answers.

Making your content dynamic with Butter is a two-step process:

  1. Set up custom content fields in Butter
  2. Integrate the fields into your application.

To set up custom content fields, first sign in to the Butter dashboard.

Create a new workspace or click on an existing one. Workspaces let you organize content fields in a friendly way for content editors and have no effect on development or the API. For example, a real estate website might have a workspace called Properties and another called About Page.

Once you’re in a workspace, click the button to create a new content field. Choose the Object type and name the field FAQ Headline.

After saving, add another field, but this time choose the Collection type and name the field FAQ Items.

On the next screen, set up two properties for items in the collection.

Now go back to your workspace and update your heading and FAQ items.

Integrate Your App

Create FAQ Component

Under apps, type ng g component faq.

apps/faq/faq.component.ts

Set up the onInit hook to load the FAQ

import {Component, OnInit} from '@angular/core';
import {butterService} from '../_services';

@Component({
selector: 'app-faq',
templateUrl: './faq.component.html',
styleUrls: ['./faq.component.scss']
})

export class FaqComponent implements OnInit {
constructor() {}

public faq: any = {
items: [],
title: 'FAQ'
};

ngOnInit() {
butterService.content.retrieve(['faq_headline', 'faq_items'])
.then((res) => {
console.log(res.data.data);
this.faq.title = res.data.data.faq_headline;
this.faq.items = res.data.data.faq_items;
});
}
}

Display the result

<mat-card>
<mat-card-title class="page-title"></mat-card-title>
<mat-divider></mat-divider>
<mat-card-content class="page-body">
<mat-card *ngFor="let item of faq.items">
<mat-card-content>
<h3>
{{item.question}}
</h3>
<div>
{{item.answer}}
</div>
</mat-card-content>
</mat-card>
</mat-card-content>
<mat-divider></mat-divider>
<mat-card-footer>
<div class="page-footer">
<mat-icon>whatshot</mat-icon>
</div>
</mat-card-footer>
</mat-card>

The values entered in the Butter dashboard will immediately update the content in our app.

Blogging

To display posts, we create a simple /blog route in your app and fetch blog posts from the Butter API, as well as a /blog/:slug route to handle individual posts.

See our API reference for additional options, such as filtering by category or author. The response also includes some metadata we’ll use for pagination.

Set Up the Blog Home Page

Under apps/blog-post, type ng g component listing.

apps/blog-post/listing/blog-post.listing.component.ts

Update the component to get all posts:

  1. import butterService
  2. get all posts onInit
import {Component, OnInit} from '@angular/core';
import {butterService} from '../../_services';

@Component({
selector: 'app-blog-post',
templateUrl: './blog-post.component.html',
styleUrls: ['./blog-post.component.scss']
})
export class BlogPostComponent implements OnInit {
public posts: any[];

constructor() { }

ngOnInit() {
butterService.post.list({
page: 1,
page_size: 10
}).then((res) => {
console.log(res.data)
this.posts = res.data.data;
});
}
}

Display the result:

<mat-card>
<mat-card-title class="page-title">Blog Posts</mat-card-title>
<mat-divider></mat-divider>
<mat-card-content class="page-body">
<mat-card *ngFor="let post of posts">
<mat-card-title>

    &lt;a [routerLink]="[post.slug]"&gt;
      &lt;div class="container"&gt;
        &lt;div fxLayout="row" fxLayout.xs="column"
           fxFlex class="content"&gt;
          &lt;div class="blocks"&gt;
            &lt;img *ngIf="post.featured_image" src="{{post.featured_image}}" height="64" width="64"/&gt;
          &lt;/div&gt;
          &lt;div class="blocks"&gt;
            {{post.title}}
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="container"&gt;
        &lt;div fxLayout="column" class="summary"&gt;
          &lt;div [innerHTML]="post.summary"&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;/mat-card-title&gt;
&lt;/mat-card&gt;

</mat-card-content>
<mat-divider></mat-divider>

<mat-card-footer>
<div class="page-footer">
<mat-icon>whatshot</mat-icon>
</div>
</mat-card-footer>
</mat-card>

Set up Blog Post Page

Under apps/blog-post, type ng g component details.

apps/blog-post/details/blog-post.details.component.ts

To show the single post:

  1. Import butterService
  2. In the OnInit hook, use butterService to get the blog-post post given the slug in the URL path
  3. Store results in the post variable and the markup (HTML) will be updated with the customer data.
import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {ActivatedRoute} from '@angular/router';
import {butterService} from '../../_services';
import {map, take} from 'rxjs/operators';

@Component({
selector: 'app-blog-post-details',
templateUrl: './blog-post.details.component.html',
styleUrls: ['./blog-post.details.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class BlogPostDetailsComponent implements OnInit {

constructor(protected route: ActivatedRoute) {
}

protected slug$: Observable&lt;string&gt;;
public post = {
    meta: null,
    data: null
};

ngOnInit() {
    this.slug$ = this.route.paramMap
        .pipe(
            map(params =&gt; (params.get('slug')))
        );

    this.slug$.pipe(
        take(1))
        .subscribe(slug =&gt; {
            butterService.post.retrieve(slug)
                .then((res) =&gt; {
                    this.post = res.data;
                }).catch((res) =&gt; {
                console.log(res);
            });
        });
}

}

Display the result:

<mat-card>
<div class="container">
<div fxLayout="column" class="blog-details">
<div class="container">
<div fxLayout="row">
<h1 class="blocks">
{{post.data.title}}
</h1>
<div *ngIf="post.meta.previous_post"><a [routerLink]="post.meta.previous_post"><</a></div>
<div *ngIf="post.meta.next_post"><a [routerLink]="post.meta.next_post">></a></div>
</div>
<h4>
{{post.data.author.first_name}} {{post.data.author.last_name}}
</h4>
<div class="post-body" [innerHTML]="post.data.body"></div>
</div>
</div>
</div>
</mat-card>

Now your app has a working blog that can be updated easily in the ButterCMS dashboard.

Categories, Tags, and Authors

Use Butter’s APIs for categories, tags, and authors to feature and filter content on your blog.

List all categories and get posts by category

Call these methods on the onInit() lifecycle hook:

methods: {
...
getCategories() {
butter.category.list()
.then((res) => {
console.log('List of Categories:')
console.log(res.data.data)
})
},
getPostsByCategory() {
butter.category.retrieve('example-category', {
include: 'recent_posts'
})
.then((res) => {
console.log('Posts with specific category:')
console.log(res)
})
}
},
created() {
...
this.getCategories()
this.getPostsByCategory()
}
Wrapping It Up

Congrats! You’ve successfully turned your static Angular application into a CMS-powered app using content APIs, thereby maintaining a serverless architecture. Your development team can take advantage of the time-saving aspects of Angular, and you’ve saved even more time by using a serverless CMS.

Thank for reading!

Important reasons for developers to adopt Angular JS development

 Important reasons for developers to adopt Angular JS development

In the current scenarios, e-commerce companies are very keen to create an online impact. The web and app development market are at its peak of popularity. There is a high demand for web and app developers with a growing number of websites. Angular...

In the current scenarios, e-commerce companies are very keen to create an online impact. The web and app development market are at its peak of popularity. There is a high demand for web and app developers with a growing number of websites. Angular has been a top choice for web development and it's the latest version AngularJS has gained popularity in the industry. This java script framework has created its prominent position in creating web apps.
Regardless of whether there are numerous different systems accessible for web development, AngularJS can support among them all. Since its introduction in the market, Angular has been creating waves in the market.

Introduction

Angular js is a powerful framework that was developed by Google. It is used to build dynamic apps with power-packed features. It was first introduced in 2010 and created by developers at Google. This framework was created to simplify and remove the challenges in creating dynamic apps. It uses HTML, CSS, and java script to create dynamic single-page applications. Angular Js is inclusive of Mongo DB and it is a frontend fragment of Mean Stack. In the developer's community, Angular is considered as a reliable and fast Java script framework. Many popular apps like PayPal. You tube, Netflix, the guardian, Lego are built using the AngularJS framework.

In this blog, we are listing some compelling reasons to pick angular development to familiarize you with its potential

• Open-source framework: It is not a library but open-source frameworks that enable the developers to build well-performing single page web applications. Just after its launch, it became hugely popular among the developers and it is not going to come at a halt.

• Simplified MVC structure: Developers use AngularJS to build robust and interactive web applications. AngularJS framework uses MVC architecture to create interactive applications. AngularJS makes it easy for developers to create apps as they are only required to split the applications.

• Extensive community: As angular is built by Google, it is backed by a very large community of professionals. The Angular JS conferences of the professionals are held all over the world. Hackathons are also organized in IT communities that include some professional and skilled engineers who can help with the queries and questions related to Angular.

• Declarative code system: In Angular JS developers can create declarative patterns by using declarative paradigms. It enables developers to be less heavy, and easy to read. In this framework, the developers get data models that are not too complex to write that abolishes the need to use any getter/setters and with easy data manipulation.

• Two-way data binding: It is one of the impeccable features that makes Angularjs popular in the developers' community. It allows seamless projections of the models and data binding. In this framework, any changes in the user interface make an impact on the application objects. The developers are not required to fresh the cycle and that makes it vulnerable to bugs.

• Using directives: AngularJS makes use of Directives as the developers can build custom HTML tags that function as custom widgets and it can be possible using directives. Its implications are also in the case of the use of decorating components and manipulation of DOM elements in appealing ways.

• Enterprise-level testing: When using Angular JS there is no need for demanding any other supplementary framework or additional plugins. In the process, parts of applications are put in the angular framework which is not too complex for manipulation. In module separation, developers can load essential services in an effective way for the performance of automatic testing.

• Client-side situation: AngularJS mainly works at the client-side and it is fully compatible with both web and mobile browsers. It can function with any projects without the need for any backend notifications. The developers can easily use AngularJS for the front end of applications.

• Easy to use: AngularJS is rich with its features and facilitates developers to reduce any need for writing codes. It reduces the burden of developers by the application of MVC architecture and data models.

Many other significant features make AngularJS prioritize by the developers than other Javascript frameworks. The above-mentioned reasons have made it the top choice for reputed companies all across the globe for web development. Developers at the company master the skills to work with Angular JS development for web. The company is equipped with dedicated professionals having sound technical knowledge of working with AngularJS. We offer offshore services to extend our reach all across the globe with various models. We have more than 15 years of experience in the industry that we use to deliver high-quality solutions by leveraging the latest technology and quality standards.

Angular JS Development Company

If you’re finding AngularJS Development Company for consultation or Development, your search ends here at Data EximIT 

🔗 Click here to know more: AngularJS Development




Top Web Application Developer

Top Web Application Developer

You can also contact a web application development company for your business but then why not to contact the best web application development company that can turn up your business and customer satisfaction ratio to sky touching heights.

Not long-ago internet came into existence and the world has never been the same ever since. The Internet made sure that people and business do evolve at a faster rate than ever and was never merciful to the slow ones. Because of this competition and availability of any business with few clicks made India one of the hubs as IT center. This trend of constantly updating has given rise to smartphones, smart machines, wearable gadgets and a lot more is yet to come in the upcoming years. In such time it is always a good idea to hire Web App Developer from India at your service. They are expert in developing not only websites but web applications as well.

We at HireFullStackDeveloperIndia, have a huge team of experienced developers that have grasped over different domains in front and back end development. You can hire web app developers in India from us with many advantages that you won’t get anywhere else in the industry.

Here is why we are the best option if you are looking forward to hiring web app developers in India:

  • Flexible hiring models available, as per your convenience and requirement
  • Maximum ROI, compared to any other company or team of developers.
  • We provide you with Source code Authorization meaning code written for you belong only to you. It cannot be used or copied anywhere else.
  • All of our developers are sound with agile development methodology, so you will be in a constant loop of suggestions, ideas, trends, and updates about your project.
  • Our developers are good with creating custom web applications as well; it guarantees you a better product without any compromise of non-existing functionalities.
  • You can save huge costing on infrastructure by utilizing our hire web app developer in India program.
  • Your hired developer or team will be easily accessible to your preferred mode of communication.
  • You get to exercise complete control over your team or individual that you hire.
  • We believe in Integrity and Transparency.
  • Our developers are highly creative and motivated to deliver excellence.


HireFullStackDeveloperIndia is a Web Application Development Company in India that is known worldwide for our Innovative guaranteed solutions. You can inquire with us about your project and we will be providing you multiple suitable developers that are the best fit for your requirements. You can evaluate them and select one or multiple whosoever deems fit to you. After this, all you have to do is provide your valuable input to the resource through sprint base project development until you get delivery of your project.

Our engagement model will also allow you to get our development team to your site location and proceed with development from your premises.