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

218
Visualizações
How to add simple onchange events on Angular 2 components

I have the component file and its templateURL html file.

In the html file I have the following code:

 <input type="range" min="0" max="20" value="0" step="1" change="showValue(this.value)" />
    <span id="range">0</span>

In the component, I have this code:

ngAfterviewInit(){
    function showValue(newValue){
        document.getElementById("range").innerHTML=newValue;
    }
}

I put the function in there, but it says its not defined. I am not sure how to define the function, and how to call it in the html file.

Any ideas? Thanks in advance, I'm quite new to A2.

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

0

<div ng-app="">
<input type="range" min="0" max="20" value="0" step="1" ng-model="rangenumber" />
<span ng-bind="rangenumber" id="range">0</span>
</div>

Component events Read this article https://toddmotto.com/component-events-event-emitter-output-angular-2

over 4 years ago · Santiago Trujillo Relatório

0

You can use ngmodel to bind your value and bind the same to span.No need to define any new functions.Please see below.

 <input type="range" min="0" max="20" [(ngModel)]="variable" step="1"  />
 <span id="range">{{variable}}</span>

you need to declare variable at component side.

Hope it helps!!

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