is it possible to put the ng-click directive within a span or a?

1

I have the following code:

     <span ng-if="contacto">Teléfono:  
         <a href="TEL://{{contacto.telefono}}">{{contacto.telefono}}</a>
         <m ng-if="contacto.extension"> Ext: 
             <a ng-repeat="ext in contacto.extension.split(';')" href="TEL://{{contacto.telefono+ext}}">{{ext}}</a>
         </m>
     </span>    

and I want to put ng-click to warn that the phone has been clicked, but I do not know if it is possible, since I tried to put ng-click on the <a> tag but it does not work for me.

in the contolador I have the following ...

     $scope.registrarllamada = function(c){
            console.log("Estamos llamando a.." + c.telefono);
    }

in the view I did this ...

     <a ng-click="registrarllamada(contacto)" href="TEL://9{{contacto.telefono}}">{{contacto.telefono}}</a>

But it does not work, I do not print anything when I click.

    
asked by Alberto Rojas 30.12.2016 в 18:21
source

3 answers

1

The instruction is not on-click, but ng-click , try the following code:

<span ng-if="contacto">Teléfono:  
     <a ng-click="alert('Clickeaste en {{contacto.telefono}}')" href="TEL://{{contacto.telefono}}">{{contacto.telefono5}}</a>
     <m ng-if="contacto.extension"> Ext: 
         <a ng-repeat="ext in contacto.extension.split(';')" href="TEL://{{contacto.telefono+ext}}">{{ext}}</a>
     </m>
 </span>   

By the way, notice that you put {{contact.phone] 5 }} That could bring you problems if it's not a declared tribute

    
answered by 30.12.2016 / 18:46
source
1

angular.module('myApp', [])
.controller("Ctrl_List", ["$scope", function(scope) {
  scope.registrarllamada = function(c){
            console.log("Estamos llamando a.." + c.telefono);
    }
}])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
 <div ng-controller="Ctrl">
  <a ng-click="registrarllamada(contacto)" href="TEL://9{{contacto.telefono}}">{{contacto.telefono}}</a>
  <span ng-if="contacto">Teléfono:  
         <a href="TEL://{{contacto.telefono}}">{{contacto.telefono}}</a>
         <m ng-if="contacto.extension"> Ext: 
             <a ng-repeat="ext in contacto.extension.split(';')" href="TEL://{{contacto.telefono+ext}}">{{ext}}</a>
         </m>
     </span> 
  </div>
</div>
    
answered by 30.12.2016 в 19:05
1

In fact it is correct what I was doing, the problem I had is another since I use ui-router and was associating another controller to that view so I could not find the $ scope.

    
answered by 30.12.2016 в 19:33