You do not need to track the index, just remove the selected category from the category model in the removeCategory function:
Your controller might look like this: JSFiddle :
app.controller("myCtrl", ['$scope', function($scope){
$scope.model = {
selectedCategory: {},
categories: [
{title: "Cat1"},
{title: "Cat2"}
]
}
$scope.model.selectedCategory = $scope.model.categories[0];
$scope.removeCategory = function(){
var ind = $scope.model.categories.indexOf( $scope.model.selectedCategory );
$scope.model.categories.splice( ind, 1 );
$scope.model.selectedCategory = $scope.model.categories[0];
}
}])
source
share