Template call javascript

#1

Hi,
I have this situation:

The template node contains a list of link (a href). I want to trigger the same function, but with different parameters. Example:

Link 1: call function('1')
Link 2: call function('2')

"function" is a function that is located in tags. Is it possible?Because nothing happened...
The source of template node is:

<script>
(function() {
function hideShowTab(scope,i) {

            scope.send({payload: {"group":{"hide":["Dashboard_Alarm_zone"],"show":["Dashboard_Dettaglio_RSSI"]},"tagId": scope.msg.payload[0]["tagId"],"timestamp" : ""}});
        }
(function(scope) {
    
       function sendId(id){
           
       }
        scope.$watch('msg.payload', function(newVal, oldVal) {
          
            $( "#alarmList" ).html("<p>Lista allarmi:</p><ul>");
            var date;
            for(var i=(scope.msg.payload[0]["timestamp"].length-1); i>=0;i--){
                console.log("----------"+scope.msg.payload[0]["timestamp"].length);
                date = new Date(scope.msg.payload[0]["timestamp"][i]);
                $( "#alarmList" ).append("<li><a href='javascript:void(0)' ng-click='javascript:sendId("+i+")'>"+date.getDate()+"/"+(date.getMonth()+1)+"/"+date.getFullYear()+" "+date.getHours()+":"+(date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes())+"</a></li>");

            }
            $( "#alarmList" ).append("</ul>");
            
        })

    })(scope)
})();
</script>
<div id="alarmList" >
    
    
</div>
0 Likes

#2

what is the console.log(scope.msg.payload) output ?

0 Likes

#3

I dont know if its important for the problem. Payload comes from the database.

0 Likes

#4

sure, but the question is, do you see output in the browser console? if not, you have your answer.

0 Likes

#5

Yes...I see the output and my html list is populated correctly

0 Likes

#6

Not sure I've understood the question properly but this may help - it shows how to bind functions to the scope.

0 Likes