Skip to content

Instantly share code, notes, and snippets.

@Dev0515
Created September 28, 2018 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dev0515/01332f41e9aac1391a7398c921a18dfa to your computer and use it in GitHub Desktop.
Save Dev0515/01332f41e9aac1391a7398c921a18dfa to your computer and use it in GitHub Desktop.
This component is fetching all data from cosmic server
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Router } from '@angular/router';
import { CosmicService } from '../../services/cosmic.service'@Component({
selector: 'app-allblogs',
templateUrl: './allblogs.component.html',
styleUrls: ['./allblogs.component.css']
})
export class AllblogsComponent implements OnInit {
data;
allBlogs;
allPosts;
author;
jdata;
constructor(private _http: Http, private route: Router, private cosmicService: CosmicService) { } //fetching all blogs from server
showAllBlogs() {
this.cosmicService.showAllBlogs()
.subscribe(res => {
this.data = res;
var jsondata = JSON.parse(this.data._body);
this.allBlogs = jsondata.objects;
console.log(this.allBlogs);
})
} loginCall() {
this.route.navigate(['login']);
} ngOnInit() { this.showAllBlogs()
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment