Skip to content
Snippets Groups Projects
Commit e107f38b authored by ramoncalabozo's avatar ramoncalabozo
Browse files

recoger datos angular a traves del backend funcionando

parent 625df934
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ import { NgChartsModule } from 'ng2-charts'; ...@@ -6,6 +6,8 @@ import { NgChartsModule } from 'ng2-charts';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { LineChartComponent } from './components/line-chart/line-chart.component'; import { LineChartComponent } from './components/line-chart/line-chart.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
...@@ -13,6 +15,7 @@ import { LineChartComponent } from './components/line-chart/line-chart.component ...@@ -13,6 +15,7 @@ import { LineChartComponent } from './components/line-chart/line-chart.component
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
HttpClientModule,
NgChartsModule NgChartsModule
], ],
providers: [], providers: [],
... ...
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ChartDataset, ChartConfiguration} from 'chart.js'; import { ChartDataset, ChartConfiguration} from 'chart.js';
import { NgChartsModule } from 'ng2-charts'; import { NgChartsModule } from 'ng2-charts';
import { UniversidadService } from '../../service/universidad.service';
import { Universidad } from '../../model/universidad';
@Component({ @Component({
selector: 'app-line-chart', selector: 'app-line-chart',
...@@ -8,7 +10,7 @@ import { NgChartsModule } from 'ng2-charts'; ...@@ -8,7 +10,7 @@ import { NgChartsModule } from 'ng2-charts';
styleUrls: ['./line-chart.component.css'] styleUrls: ['./line-chart.component.css']
}) })
export class LineChartComponent implements OnInit{ export class LineChartComponent implements OnInit{
private universidades!: Universidad[]
lineChartData: ChartDataset[] = [ // Datos lineChartData: ChartDataset[] = [ // Datos
{ data: [12, 72, 78, 75, 17, 75], label: 'Crude oil prices' }, { data: [12, 72, 78, 75, 17, 75], label: 'Crude oil prices' },
{ data: [85, 12, 28, 85, 17, 75], label: 'Another crud' } { data: [85, 12, 28, 85, 17, 75], label: 'Another crud' }
...@@ -23,8 +25,21 @@ export class LineChartComponent implements OnInit{ ...@@ -23,8 +25,21 @@ export class LineChartComponent implements OnInit{
lineChartType = 'line'; lineChartType = 'line';
constructor() {} constructor(
private UniversidadService: UniversidadService
) {}
ngOnInit():void { ngOnInit():void {
this.getUniversidades();
}
getUniversidades(){
this.UniversidadService.getAllUniversidades().subscribe((d) =>{
// console.log(d);
/*this.lineChartData = [ // Datos
{ data: [12, 72, 78, 75, 17, 75], label: 'Crude oil prices' },
{ data: [85, 12, 28, 85, 17, 75], label: 'Another crud' }
];*/
});
} }
shuffeData() { shuffeData() {
... ...
......
...@@ -12,6 +12,4 @@ export interface Universidad { ...@@ -12,6 +12,4 @@ export interface Universidad {
dosmilveinte: number, dosmilveinte: number,
totalPublicaciones: number, totalPublicaciones: number,
promedioPublicaciones: number promedioPublicaciones: number
} }
\ No newline at end of file
import { Injectable } from '@angular/core';
import { Universidad } from '../model/universidad';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class UniversidadService {
constructor(
private http: HttpClient
) { }
getAllUniversidades(): Observable<Universidad[]> {
return this.http.get<Universidad[]>(`${environment.url}`)
}
}
export const environment = {
production: false,
url: 'http://localhost:8000/allUniversidades/' // recoge todas las Universidades
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment