javascript - Angular - how to set up click event on the start -
i want append click event li (list) elements (i have ordered list - ul). using angular controller. strange thing doesnt work. here's part of code setting event (inside angular controller):
$document.ready(function () { $scope.getallnotes(); $scope.addsortable(); $scope.setevents(); //function call function click event li loader.hide(); $window.focus(); })
function click event:
$scope.setevents = function () { jquery("#ulnotes li").click(function () { alert("you've clicked li!"); }); }
i guess if doesn't work can still use iife, believe there must angular way this.
don't use jquery angular tushar stated.
html:
<div ng-controller="samplecontroller"> <ul ng-repeat="item in items"> <!-- assuming you're looping through list' --> <li ng-click="clickfunction($index)">click me!</li> </ul> </div>
js:
(function() { 'use strict'; angular .module('mymodule') .controller('samplecontroller', controllercontroller); controllercontroller.$inject = ['$scope']; function controllercontroller($scope) { $scope.items = []; // list of items $scope.clickfunction = function(index) { alert("you've clicked list item: " + index); } } })();
Comments
Post a Comment