浏览代码

Partial commit --- News service to fetch data from Punjab kings website [Current issue = CORS]

master
kj1352 4 年前
父节点
当前提交
66c7885300
共有 8 个文件被更改,包括 1592 次插入1595 次删除
  1. +1563
    -1561
      .firebase/hosting.d3d3.cache
  2. +2
    -2
      src/app/app.module.ts
  3. +4
    -1
      src/app/home/home.page.ts
  4. +0
    -25
      src/app/services/data.service.ts
  5. +4
    -4
      src/app/services/news.service.spec.ts
  6. +17
    -0
      src/app/services/news.service.ts
  7. +1
    -1
      src/app/tabs/tabs-routing.module.ts
  8. +1
    -1
      src/app/tabs/tabs.page.html

+ 1563
- 1561
.firebase/hosting.d3d3.cache
文件差异内容过多而无法显示
查看文件


+ 2
- 2
src/app/app.module.ts 查看文件

@@ -16,7 +16,7 @@ import { environment } from '../environments/environment';
import { MyHammerConfig } from './hammer-config'; import { MyHammerConfig } from './hammer-config';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';


import { DataService } from './services/data.service';
import { NewsService } from './services/news.service';


import { GooglePlus } from '@ionic-native/google-plus/ngx'; import { GooglePlus } from '@ionic-native/google-plus/ngx';


@@ -45,7 +45,7 @@ var firebaseConfig = {
StatusBar, StatusBar,
SplashScreen, SplashScreen,
GooglePlus, GooglePlus,
DataService,
NewsService,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{ provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig }, { provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig },
], ],


+ 4
- 1
src/app/home/home.page.ts 查看文件

@@ -1,7 +1,7 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { IonSlides, ModalController } from '@ionic/angular'; import { IonSlides, ModalController } from '@ionic/angular';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ChatPage } from '../chat/chat.page';
import { NewsService } from '../services/news.service';


export type INews = { export type INews = {
id: string | number, id: string | number,
@@ -50,9 +50,12 @@ export class HomePage implements OnInit {
constructor( constructor(
private router: Router, private router: Router,
private modalController: ModalController, private modalController: ModalController,
private newsService: NewsService
) { } ) { }


ngOnInit() { ngOnInit() {
this.newsService.getArticles().then((data) => console.log(data));

this.newsData = [{ this.newsData = [{
id: 1, id: 1,
image: 'https://www.kxip.in/static-assets/waf-images/c3/b2/7d/16-9/DWWfHZsFg1.jpg', image: 'https://www.kxip.in/static-assets/waf-images/c3/b2/7d/16-9/DWWfHZsFg1.jpg',


+ 0
- 25
src/app/services/data.service.ts 查看文件

@@ -1,25 +0,0 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
providedIn: 'root'
})
export class DataService {

constructor(
private http: HttpClient
) { }


getPosts() {
const httpOptions = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
})
};
return this.http.get('https://www.kxip.in/api/flowicsproxy?url=https://live.flowics.com/api/content/0.2/flows/d0184b7bd3e021a4b557d6cb2d33a6ec/posts', httpOptions).toPromise();
}

}


src/app/services/data.service.spec.ts → src/app/services/news.service.spec.ts 查看文件

@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';


import { DataService } from './data.service';
import { NewsService } from './news.service';


describe('DataService', () => {
let service: DataService;
describe('NewsService', () => {
let service: NewsService;


beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({});
service = TestBed.inject(DataService);
service = TestBed.inject(NewsService);
}); });


it('should be created', () => { it('should be created', () => {

+ 17
- 0
src/app/services/news.service.ts 查看文件

@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
providedIn: 'root'
})
export class NewsService {

constructor(
private http: HttpClient
) { }


getArticles() {
return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10').toPromise();
}
}

+ 1
- 1
src/app/tabs/tabs-routing.module.ts 查看文件

@@ -23,7 +23,7 @@ const routes: Routes = [
}, },
{ {
path: '', path: '',
redirectTo: '/tabs/live',
redirectTo: '/tabs/home',
pathMatch: 'full' pathMatch: 'full'
} }
]; ];


+ 1
- 1
src/app/tabs/tabs.page.html 查看文件

@@ -1,7 +1,7 @@
<ion-tabs #tabs (ionTabsDidChange)="setCurrentTab()"> <ion-tabs #tabs (ionTabsDidChange)="setCurrentTab()">
<ion-tab-bar slot="bottom" [ngClass]="{'live' : selectedTab === 'live', <ion-tab-bar slot="bottom" [ngClass]="{'live' : selectedTab === 'live',
'dark' : selectedTab === 'player-stats'}"> 'dark' : selectedTab === 'player-stats'}">
<ion-tab-button tab="home" disabled="true">
<ion-tab-button tab="home">
<ion-icon name="home-outline"></ion-icon> <ion-icon name="home-outline"></ion-icon>
<ion-icon name="home"></ion-icon> <ion-icon name="home"></ion-icon>
</ion-tab-button> </ion-tab-button>


正在加载...
取消
保存