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

124
Visualizações
How to pass variables from one page to another with AngularJS?

I'm working with 2 different controllers (and js files) for my index.html (controllerIndex on index.js) and pageA.html (controllerPageA on pageA.js).

index.html has 2 links that lead to the same page, but need to pass a parameter with different values depending on which one I click in order to use them for an API on controller2.

How can I do this?

index.html:

<!-- Should pass ParameterA here -->
<a ng-model="parameter" ng-init="parameter = 'parameterA'" href="pageA.html">Page A1</a> 
<!-- Should pass ParameterB here -->
<a ng-model="parameter" ng-init="parameter = 'parameterB'" href="pageA.html">Page A2</a>

pageA.js:

$http({
  method: 'GET',
  url: 'localhost:8888/ProjectName/API/items/list?type=' + parameter //where parameter = 'parameterA' or 'parameterB' depending on which link was clicked
}).then(function successCallback(response) {
   $scope.items = response.data;
  }, function errorCallback(response) {
    alert("Error");
  }); 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not familiar with Angular. But it looks to me that you can transfer your parameters simply via GET-parameters:

<a ng-model="parameter" ng-init="parameter = 'parameterA'" href="pageA.html?parameter=parameterA">Page A1</a> 

and retreive them like this on the pageA.html:

   var query = window.location.search.substring(1);
   var parts = query.split("=");
   var parameter = parts[1];
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