Angular - employees does no appear in component
I'm trying to show register employees in my angular app, but it doesn't appear the values, only creates their items of the array, i make a console.log to see what's wrong and it looks like to be the variables are undefined. Help please
empleado.component.html
<div class="row animated fadeIn">
<div class="col-12">
<div class="card">
<div class="card-body">
<h3 class="card-title"> Empleados registrados </h3>
<table class="table table-hover" >
<thead>
<tr>
<th>Nombre</th>
<th>Codigo</th>
<th>Posicion</th>
<th>Oficina</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let empleado of empleados">
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
empleado.component.ts
import { Component, OnInit } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { EmpleadoService } from '../services/empleado.service';
@Component({
selector: 'app-empleado',
templateUrl: './empleado.component.html',
styleUrls: ['./empleado.component.css']
})
export class EmpleadoComponent implements OnInit {
empleados: any = ;
constructor(public empleadoServ: EmpleadoService) { }
ngOnInit() {
this.traerEmpleados();
console.log(this.empleados.length);
}
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
console.log(resp[0].nombre);
for (let index = 0; index < resp.length; index++) {
this.empleados[index] = resp[index];
console.log(this.empleados[index]);
}
// JSON.stringify(this.empleados);
console.log(this.empleados[0].nombre);
});
}
}
empleado.service.ts
import { Injectable } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import swal from 'sweetalert';
@Injectable({
providedIn: 'root'
})
export class EmpleadoService {
constructor(public http: HttpClient) { }
guardarEmpleado(empleado: Empleado): Observable<any> {
return this.http.post('http://localhost:62200/api/Empleado', empleado)
.pipe(
map( (resp: any) => {
swal('Empleado creado', empleado.nombre, 'success');
return empleado;
}),
catchError((e: any) => throwError(e))
);
}
getEmpleados() {
return this.http.get('http://localhost:62200/api/Empleado');
}
borrarEmpleado(id: number): Observable <any> {
return this.http.delete('http://localhost:62200/api/Empleado/' + id)
.pipe(
map( (resp: any) => {
swal('Empleado eliminado', 'Borrado', 'warning');
return resp;
}),
catchError((e: any) => throwError(e))
);
}
}
And when i try to show employees, it creates the items but it doesn't show the name, code, position, office.
angular typescript
add a comment |
I'm trying to show register employees in my angular app, but it doesn't appear the values, only creates their items of the array, i make a console.log to see what's wrong and it looks like to be the variables are undefined. Help please
empleado.component.html
<div class="row animated fadeIn">
<div class="col-12">
<div class="card">
<div class="card-body">
<h3 class="card-title"> Empleados registrados </h3>
<table class="table table-hover" >
<thead>
<tr>
<th>Nombre</th>
<th>Codigo</th>
<th>Posicion</th>
<th>Oficina</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let empleado of empleados">
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
empleado.component.ts
import { Component, OnInit } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { EmpleadoService } from '../services/empleado.service';
@Component({
selector: 'app-empleado',
templateUrl: './empleado.component.html',
styleUrls: ['./empleado.component.css']
})
export class EmpleadoComponent implements OnInit {
empleados: any = ;
constructor(public empleadoServ: EmpleadoService) { }
ngOnInit() {
this.traerEmpleados();
console.log(this.empleados.length);
}
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
console.log(resp[0].nombre);
for (let index = 0; index < resp.length; index++) {
this.empleados[index] = resp[index];
console.log(this.empleados[index]);
}
// JSON.stringify(this.empleados);
console.log(this.empleados[0].nombre);
});
}
}
empleado.service.ts
import { Injectable } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import swal from 'sweetalert';
@Injectable({
providedIn: 'root'
})
export class EmpleadoService {
constructor(public http: HttpClient) { }
guardarEmpleado(empleado: Empleado): Observable<any> {
return this.http.post('http://localhost:62200/api/Empleado', empleado)
.pipe(
map( (resp: any) => {
swal('Empleado creado', empleado.nombre, 'success');
return empleado;
}),
catchError((e: any) => throwError(e))
);
}
getEmpleados() {
return this.http.get('http://localhost:62200/api/Empleado');
}
borrarEmpleado(id: number): Observable <any> {
return this.http.delete('http://localhost:62200/api/Empleado/' + id)
.pipe(
map( (resp: any) => {
swal('Empleado eliminado', 'Borrado', 'warning');
return resp;
}),
catchError((e: any) => throwError(e))
);
}
}
And when i try to show employees, it creates the items but it doesn't show the name, code, position, office.
angular typescript
add a comment |
I'm trying to show register employees in my angular app, but it doesn't appear the values, only creates their items of the array, i make a console.log to see what's wrong and it looks like to be the variables are undefined. Help please
empleado.component.html
<div class="row animated fadeIn">
<div class="col-12">
<div class="card">
<div class="card-body">
<h3 class="card-title"> Empleados registrados </h3>
<table class="table table-hover" >
<thead>
<tr>
<th>Nombre</th>
<th>Codigo</th>
<th>Posicion</th>
<th>Oficina</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let empleado of empleados">
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
empleado.component.ts
import { Component, OnInit } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { EmpleadoService } from '../services/empleado.service';
@Component({
selector: 'app-empleado',
templateUrl: './empleado.component.html',
styleUrls: ['./empleado.component.css']
})
export class EmpleadoComponent implements OnInit {
empleados: any = ;
constructor(public empleadoServ: EmpleadoService) { }
ngOnInit() {
this.traerEmpleados();
console.log(this.empleados.length);
}
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
console.log(resp[0].nombre);
for (let index = 0; index < resp.length; index++) {
this.empleados[index] = resp[index];
console.log(this.empleados[index]);
}
// JSON.stringify(this.empleados);
console.log(this.empleados[0].nombre);
});
}
}
empleado.service.ts
import { Injectable } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import swal from 'sweetalert';
@Injectable({
providedIn: 'root'
})
export class EmpleadoService {
constructor(public http: HttpClient) { }
guardarEmpleado(empleado: Empleado): Observable<any> {
return this.http.post('http://localhost:62200/api/Empleado', empleado)
.pipe(
map( (resp: any) => {
swal('Empleado creado', empleado.nombre, 'success');
return empleado;
}),
catchError((e: any) => throwError(e))
);
}
getEmpleados() {
return this.http.get('http://localhost:62200/api/Empleado');
}
borrarEmpleado(id: number): Observable <any> {
return this.http.delete('http://localhost:62200/api/Empleado/' + id)
.pipe(
map( (resp: any) => {
swal('Empleado eliminado', 'Borrado', 'warning');
return resp;
}),
catchError((e: any) => throwError(e))
);
}
}
And when i try to show employees, it creates the items but it doesn't show the name, code, position, office.
angular typescript
I'm trying to show register employees in my angular app, but it doesn't appear the values, only creates their items of the array, i make a console.log to see what's wrong and it looks like to be the variables are undefined. Help please
empleado.component.html
<div class="row animated fadeIn">
<div class="col-12">
<div class="card">
<div class="card-body">
<h3 class="card-title"> Empleados registrados </h3>
<table class="table table-hover" >
<thead>
<tr>
<th>Nombre</th>
<th>Codigo</th>
<th>Posicion</th>
<th>Oficina</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let empleado of empleados">
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
empleado.component.ts
import { Component, OnInit } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { EmpleadoService } from '../services/empleado.service';
@Component({
selector: 'app-empleado',
templateUrl: './empleado.component.html',
styleUrls: ['./empleado.component.css']
})
export class EmpleadoComponent implements OnInit {
empleados: any = ;
constructor(public empleadoServ: EmpleadoService) { }
ngOnInit() {
this.traerEmpleados();
console.log(this.empleados.length);
}
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
console.log(resp[0].nombre);
for (let index = 0; index < resp.length; index++) {
this.empleados[index] = resp[index];
console.log(this.empleados[index]);
}
// JSON.stringify(this.empleados);
console.log(this.empleados[0].nombre);
});
}
}
empleado.service.ts
import { Injectable } from '@angular/core';
import { Empleado } from '../models/empleado.model';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import swal from 'sweetalert';
@Injectable({
providedIn: 'root'
})
export class EmpleadoService {
constructor(public http: HttpClient) { }
guardarEmpleado(empleado: Empleado): Observable<any> {
return this.http.post('http://localhost:62200/api/Empleado', empleado)
.pipe(
map( (resp: any) => {
swal('Empleado creado', empleado.nombre, 'success');
return empleado;
}),
catchError((e: any) => throwError(e))
);
}
getEmpleados() {
return this.http.get('http://localhost:62200/api/Empleado');
}
borrarEmpleado(id: number): Observable <any> {
return this.http.delete('http://localhost:62200/api/Empleado/' + id)
.pipe(
map( (resp: any) => {
swal('Empleado eliminado', 'Borrado', 'warning');
return resp;
}),
catchError((e: any) => throwError(e))
);
}
}
And when i try to show employees, it creates the items but it doesn't show the name, code, position, office.
angular typescript
angular typescript
edited Nov 22 '18 at 17:46
Niladri
3,85721428
3,85721428
asked Nov 22 '18 at 17:36
Leonardo BLeonardo B
354
354
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
In your markup, you are using lowercase property names:
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
Yet in the screenshot, it seems the data objects returned from the server are in uppercase.
If you change your markup to use the uppercase property names (empleado.Nombre
, etc.) I suspect that will do the trick.
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
add a comment |
Properties are case sensitive
For example change empleado.nombre to empleado.Nombre
<tr *ngFor="let empleado of empleados">
<td>{{empleado.Nombre}}</td>
<td>{{empleado.Codigo}}</td>
<td>{{empleado.Posicion}}</td>
<td>{{empleado.Oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
add a comment |
why are you displaying alert msg in Service. It should be added in Component.
did console.log in service returns result? If yes, try with below code.
Component:
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
this.empleados = resp;
});
}
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435953%2fangular-employees-does-no-appear-in-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your markup, you are using lowercase property names:
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
Yet in the screenshot, it seems the data objects returned from the server are in uppercase.
If you change your markup to use the uppercase property names (empleado.Nombre
, etc.) I suspect that will do the trick.
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
add a comment |
In your markup, you are using lowercase property names:
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
Yet in the screenshot, it seems the data objects returned from the server are in uppercase.
If you change your markup to use the uppercase property names (empleado.Nombre
, etc.) I suspect that will do the trick.
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
add a comment |
In your markup, you are using lowercase property names:
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
Yet in the screenshot, it seems the data objects returned from the server are in uppercase.
If you change your markup to use the uppercase property names (empleado.Nombre
, etc.) I suspect that will do the trick.
In your markup, you are using lowercase property names:
<td>{{empleado.nombre}}</td>
<td>{{empleado.codigo}}</td>
<td>{{empleado.posicion}}</td>
<td>{{empleado.oficina}}</td>
Yet in the screenshot, it seems the data objects returned from the server are in uppercase.
If you change your markup to use the uppercase property names (empleado.Nombre
, etc.) I suspect that will do the trick.
answered Nov 22 '18 at 17:48
Myk WillisMyk Willis
5,95412037
5,95412037
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
add a comment |
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
Thank you, it works. I cannot believe that was the problem.
– Leonardo B
Nov 22 '18 at 18:09
add a comment |
Properties are case sensitive
For example change empleado.nombre to empleado.Nombre
<tr *ngFor="let empleado of empleados">
<td>{{empleado.Nombre}}</td>
<td>{{empleado.Codigo}}</td>
<td>{{empleado.Posicion}}</td>
<td>{{empleado.Oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
add a comment |
Properties are case sensitive
For example change empleado.nombre to empleado.Nombre
<tr *ngFor="let empleado of empleados">
<td>{{empleado.Nombre}}</td>
<td>{{empleado.Codigo}}</td>
<td>{{empleado.Posicion}}</td>
<td>{{empleado.Oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
add a comment |
Properties are case sensitive
For example change empleado.nombre to empleado.Nombre
<tr *ngFor="let empleado of empleados">
<td>{{empleado.Nombre}}</td>
<td>{{empleado.Codigo}}</td>
<td>{{empleado.Posicion}}</td>
<td>{{empleado.Oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
Properties are case sensitive
For example change empleado.nombre to empleado.Nombre
<tr *ngFor="let empleado of empleados">
<td>{{empleado.Nombre}}</td>
<td>{{empleado.Codigo}}</td>
<td>{{empleado.Posicion}}</td>
<td>{{empleado.Oficina}}</td>
<td>
<button class="btn btn-primary"> <i class="fa fa-save"></i></button>
<button class="btn btn-danger"> <i class="fa fa-trash-o"></i></button>
</td>
</tr>
answered Nov 22 '18 at 17:46
Code-EZCode-EZ
3,44593254
3,44593254
add a comment |
add a comment |
why are you displaying alert msg in Service. It should be added in Component.
did console.log in service returns result? If yes, try with below code.
Component:
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
this.empleados = resp;
});
}
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
add a comment |
why are you displaying alert msg in Service. It should be added in Component.
did console.log in service returns result? If yes, try with below code.
Component:
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
this.empleados = resp;
});
}
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
add a comment |
why are you displaying alert msg in Service. It should be added in Component.
did console.log in service returns result? If yes, try with below code.
Component:
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
this.empleados = resp;
});
}
why are you displaying alert msg in Service. It should be added in Component.
did console.log in service returns result? If yes, try with below code.
Component:
traerEmpleados() {
this.empleadoServ.getEmpleados()
.subscribe( (resp: any) => {
this.empleados = resp;
});
}
answered Nov 22 '18 at 17:41
Suresh Kumar AriyaSuresh Kumar Ariya
4,8061216
4,8061216
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
add a comment |
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
It always get error, the problem that i see, it's maybe in the types, when I write console.log(this.empleados[0].nombre); it appears in the console "undefined"
– Leonardo B
Nov 22 '18 at 17:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435953%2fangular-employees-does-no-appear-in-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown