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

143
Visualizações
How to detect which directive element was clicked from the controller?

I have an html template including an angularJS directive

<div my-users="users" ng-click="onUserClick()"></div>

the directive renders 2 elements, for example

[... code from the directive]
template:
'<div><input type="text" class="text1"><input type="text" class="text2"></div>'

I need to know, inside the controller, which of the input fileds in the directive was clicked

$scope.onUserClick = function() {
// what should I put here?
}

is it possible?

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

0

You can detect what element was clicked using the $event parameter. This gives you a jQuery EventObject that you can inspect the element clicked using $event.target. But this will not be linked to the directive. If you want to tie click behaviors from the directive and expose that behavior to the parent controller, you should be using callbacks passed to directive behaviors (scroll down the the part using the &)

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