Procházet zdrojové kódy

load api news page

golf %!s(int64=3) %!d(string=před) roky
rodič
revize
563744429f

+ 14 - 1
src/app/news/news.page.ts

1
 import { Component, OnInit } from '@angular/core';
1
 import { Component, OnInit } from '@angular/core';
2
+import { WpdataService} from '../services/wpdata.service';
3
+import { Observable } from 'rxjs';
4
+import { map } from 'rxjs/operators';
2
 
5
 
3
 @Component({
6
 @Component({
4
   selector: 'app-news',
7
   selector: 'app-news',
7
 })
10
 })
8
 export class NewsPage implements OnInit {
11
 export class NewsPage implements OnInit {
9
 
12
 
10
-  constructor() { }
13
+  newsdata: any;
14
+  // data: Observable;
15
+
16
+  constructor(private wpgetdataService: WpdataService) { }
11
 
17
 
12
   ngOnInit() {
18
   ngOnInit() {
19
+    this.wpgetdataService.getAllNews().subscribe(data => {
20
+      // this.jsonService.getSummaryData().subscribe((data) => {      
21
+      // this.newsdata = data;
22
+      // console.log('load Static Data');
23
+      console.log("get News:");
24
+      console.log(data);
25
+    });
13
   }
26
   }
14
 
27
 
15
 }
28
 }

+ 9 - 1
src/app/services/wpdata.service.ts

1
 import { Injectable } from '@angular/core';
1
 import { Injectable } from '@angular/core';
2
+import { Observable } from 'rxjs';
3
+import { map } from 'rxjs/operators';
2
 import { HttpClient, HttpHeaders } from '@angular/common/http';
4
 import { HttpClient, HttpHeaders } from '@angular/common/http';
3
 
5
 
4
 @Injectable({
6
 @Injectable({
6
 })
8
 })
7
 export class WpdataService {
9
 export class WpdataService {
8
 
10
 
9
-  constructor() { }
11
+  constructor(private http: HttpClient) { }
12
+
13
+  getAllNews() {
14
+    return this.http.get(
15
+      "../assets/api/news-api.json"      
16
+    );
17
+  }
10
 }
18
 }

+ 1 - 2
src/assets/api/news-api.json

1
-// 20221027103152
2
-// https://fm99activeradio.mcot.net/wp-json/wp/v2/news?_embed
1
+
3
 [
2
 [
4
     {
3
     {
5
         "id": 10560,
4
         "id": 10560,