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

290
Visualizações
Type 'URLSearchParams' is not assignable to type 'URLSearchParams'

I want to send a http.get request with some search parameters to my webapi to get a list of students. I found some examples on how to do this, but after doing exactly as in the examples, I get this weird error:

Type 'URLSearchParams' is not assignable to type 'URLSearchParams'. Two different types with this name exist, but they are unrelated.
Property 'rawParams' is missing in type 'URLSearchParams'.

Here's my component:

import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map'
import { User } from '../_models/user';

@Injectable()
export class UserService {

options = new RequestOptions({ 'headers': new Headers({ 'Content-Type': 'application/json' })});

constructor(private http: Http) {
}

createAccount(newUser: User){
return this.http.post('http://localhost:64792/api/students', JSON.stringify(newUser), this.options)
.map((response: Response) => {              
    if(response.ok){
        console.log("Registration was a success");
        return true;
     } else {
         console.log("Registration failed");
         return false;
      }
 });
}

searchStudents(searchWords: Array<string>){
// Parameters obj-
 let params: URLSearchParams = new URLSearchParams();
 for(let i = 0; i < searchWords.length; i++){
 params.append('searchWords', searchWords[i]);
 }
 this.options.search = params;
 //Http request-
}
} 

What could be causing this error?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It seems the native URLSearchParams is declared to your present code, whereas the new URLSearchParams(); returns angular.io's URLSearchParams object

import 'rxjs/add/operator/map' and it should work.

import { URLSearchParams } from '@angular/http';
over 4 years ago · Santiago Trujillo Relatório

0

Try using set method

searchStudents(searchWords: Array<string>){
// Parameters obj-
 let params: URLSearchParams = new URLSearchParams();
 for(let i = 0; i < searchWords.length; i++){
 params.set('searchWords', searchWords[i]);
 }
 this.options.search = params;
 //Http request-
}
over 4 years ago · Santiago Trujillo 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