Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
change value of params when calling function angular

I need to change the value of params for pageNumber and titulo when i call one of the functions below... but when i call the functions these params remains the same, example

http://miurl.com/jsonapi/views/busqueda_avanzada/informes?page=${this.pageNumber}&views-filter[titulo]=${this.titulo}; //pageNumber returns 0 which is the initial value, but when i call getPage() function still returns 0 when it should return 1 and then 2, for each call. The idea is to create a search filter with Angular. Hope you can give me some clue of what im doing wrong! Thanks

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

export interface InformesCounter {
  data: any;
  meta: any;
  count: any;
  attributes: any;
  links: any;
  next: any;
  href: any;
  titulo: any;
}

@Injectable({
  providedIn: 'root'
})

export class BuscadorService {
  pageNumber: any = 0;
  titulo: any = '';
  informesNodes =`http://miurl.com/jsonapi/views/busqueda_avanzada/informes?page=${this.pageNumber}&views-filter[titulo]=${this.titulo}`;

  constructor(private http: HttpClient) { }
  
  getNodes(): Observable<InformesCounter> {
    this.pageNumber = 1;
    return this.http.get<InformesCounter>(`${this.informesNodes}`);
  }

  getFiltered(titulo: any): Observable<InformesCounter> {
    this.titulo = titulo;
    this.pageNumber = 1;
    return this.http.get<InformesCounter>(`${this.informesNodes}`);
  }

  getPage(): Observable<InformesCounter> {
    this.pageNumber = this.pageNumber + 1;
    return this.http.get<InformesCounter>(`${this.informesNodes}`);
  }

  ungetPage(): Observable<InformesCounter> {
    this.pageNumber = this.pageNumber - 1;
    return this.http.get<InformesCounter>(`${this.informesNodes}`);
  }

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your informesNodes template string only gets evaluated once, when the class instance is created. It is not automatically updated with new information.

An easy solution would be to replace it with a getter and the rest of your code can stay as-is:

get informesNodes() {
    return `http://miurl.com/jsonapi/views/busqueda_avanzada/informes?page=${this.pageNumber}&views-filter[titulo]=${this.titulo}`;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda