Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
La propiedad 'suscribir' no existe en el tipo 'vacío' en angular-cli

Soy nuevo en angular 2 y no encontré ninguna respuesta adecuada para preguntas similares publicadas.

Obtengo que la propiedad 'suscribirse' no existe en el tipo 'vacío' en angular-cli. Intenté importar la suscripción desde rxjs pero no encontré esa biblioteca.

Imagen de error

por favor ayuda a resolver este problema. encuentre a continuación mi servicio y el código de componente en el que estoy llamando a ese servicio.

 // ******************************* // login.service.ts // ******************************* import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Observable } from 'rxjs/observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/throw'; @Injectable() export class LoginService { constructor(private http: Http) { } getLoginData(){ this.http.get('./json/login.json') .map((result: Response) => result.json()) .catch(this.getError); } private getError(error: Response): Observable<any>{ console.log(error); return Observable.throw(error.json() || 'Server Issue'); } } // ******************************* // login.component.ts // ******************************* import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { LoginService } from '../login.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'], providers: [LoginService] }) export class LoginComponent { usernameModel: string; passwordModel: string; validLogin: Boolean; constructor(private router: Router, private loginService: LoginService) { } homeNav(){ if(this.usernameModel === 'jay' && this.passwordModel === 'Jay'){ this.validLogin = true; this.router.navigate(['/home']); } else{ this.validLogin = false; console.log('Login Error'); } this.loginService.getLoginData() .subscribe( data => console.log(data) ); } }

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

No está devolviendo el observable en su función getLoginData . Agregue la palabra clave de return y, opcionalmente, agregue el tipo de devolución a la firma:

 getLoginData(): Observable<any>{ return this.http.get('./json/login.json') .map((result: Response) => result.json()) .catch(this.getError); }
about 4 years ago · Santiago Trujillo Report

0

Debe devolver la llamada http y asegurarse de agregar siempre sugerencias de tipo para que su IDE detecte estos errores de antemano.

 getLoginData(): Observable<any> { return this.http.get('./json/login.json') .map((result: Response) => result.json()) .catch(this.getError); }
about 4 years ago · Santiago Trujillo Report

0

estoy usando angular 13

[Post.servicios.ts]

Retorno de uso simple en la API

postProducto (datos: cualquiera) {

 return this.http.post<any>(" http://localhost:3000/productList/", data)

}

[Post.componente.ts]

Agregar producto(){

 if(this.productForm.valid){ this.API_DailogService.postProduct(this.productForm.value) .subscribe({ next:()=>{ alert("Product added successfully!") }, error: () =>{ alert("Error while adding product!") } }) }

}

[Post.component.html]

<button (clic)="addProduct()">Guardar

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!