javascript - AngularJS : Want to disable the link when it clicked once -
i have list , each item of list clickable.
i want each item should clickable 1 time.
once click on it, disable or not clickable second time.
my code folowing:
<li data-ng-repeat="item in items"> <a id="{{item.id}}" data-ng-click="insertrecord(item.id)" data-ng-controller="addctrl"> {{item.name}} </a> </li>
flim's answer almost works since addctrl creates isolate scope, need define seenids on scope controller contains addctrl. here working solution:
the html:
<div ng-app ng-controller="mainctrl"> <ul> <li data-ng-repeat="item in items"> <a id="{{item.id}}" data-ng-controller="addctrl" data-ng-click="item.clicked || insertrecord(item.id); item.clicked = true"> {{item.name}} </a> </li> </ul> </div> the js:
function mainctrl($scope) { $scope.items = [ {id: 1, name: 'foo'}, {id: 2, name: 'bar'} ]; $scope.insertrecord = function(itemid) { alert(itemid + ' clicked (inserting...)'); }; } function addctrl($scope) { }
Comments
Post a Comment