I have an angularjs page which has an ng-repeat <ul> list of data points. Each <li> has a Delete link (call this Delete 1) which when clicked needs to hide that Delete 1 link and show 2 more links in its place: Cancel and Delete (call this Delete 2). When the Cancel link is clicked, the original Delete 1 link needs to show and the Cancel and Delete 2 links need to hide. All this currently works, but now there is a new requirement.
When Delete 1 link is clicked all "Cancel and Delete 2" link pairs on other list items need to hide. As AngularJS is single action based, I create a function for deleteLinkClick and cancelLinkClick to make the required complex actions.
When you look at the controller code provided below you see the show flag being set to false, but it does not work. Suggestions?
Here is my (slim) html page:
... OTHER STUFF...
ul
li.address ng-repeat="data in request.theData" ng-init="showWarning=[]"
.address-li
.address-details
p
|Field 1: {{data.field1}}
span ng-if="data.field2!=''"
br
|Field 2: {{data.field2}}
span
span.button-small.button-cancel ng-show="!showWarning[$index]" ng-click="deleteLinkClick(showWarning,$index)" Delete
span.button-small.button-cancel ng-show="showWarning[$index]" ng-click="cancelLinkClick(showWarning,$index)" Cancel
span.button-small.button-delete.button-warn ng-show="showWarning[$index]" ng-click="deleteAddress($index)" Delete
... OTHER STUFF...
Here is my (coffeescript) controller code:
@MyPage.controller('MyController',
['$scope', '$rootScope', '$location', 'NtdRequest', 'Form', '$anchorScroll'
($scope, $rootScope, $location, ntd_request, form, $anchorScroll) ->
$scope.currentIndex = -1
$scope.cancelLinkClick = (array,index) ->
array[index] = false
$scope.currentIndex = -1
$scope.deleteLinkClick = (array,index) ->
if ($scope.currentIndex != -1)
array[$scope.currentIndex] = false
array[index] = true
$scope.currentIndex = index
]
)
Thank you in advance
-wh