浏览代码

Data Service Added

master
kj1352 4 年前
父节点
当前提交
64b68eb392
共有 3 个文件被更改,包括 46 次插入0 次删除
  1. +5
    -0
      src/app/app.module.ts
  2. +16
    -0
      src/app/services/data.service.spec.ts
  3. +25
    -0
      src/app/services/data.service.ts

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

@@ -11,6 +11,9 @@ import { AppComponent } from './app.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { MyHammerConfig } from './hammer-config';
import { HttpClientModule } from '@angular/common/http';

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

@NgModule({
declarations: [AppComponent],
@@ -18,11 +21,13 @@ import { MyHammerConfig } from './hammer-config';
imports: [BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule,
HammerModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })],
providers: [
StatusBar,
SplashScreen,
DataService,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{ provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig },
],


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

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

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

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

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

it('should be created', () => {
expect(service).toBeTruthy();
});
});

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

@@ -0,0 +1,25 @@
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();
}

}


正在加载...
取消
保存