Created
September 28, 2018 07:13
-
-
Save Dev0515/01332f41e9aac1391a7398c921a18dfa to your computer and use it in GitHub Desktop.
This component is fetching all data from cosmic server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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