I'm currently facing an issue where I am unable to delete data from an input field.
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function MyCtrl($scope) {
$scope.items = [
{
name: 'item 1',
id: '4'
},
{
name: 'item 2',
id: '3'
},
{
name: 'item 3',
id: '2'
},
{
name: 'item 4',
id: '1'
}
];
$scope.delete = function (item) {
$scope.items.splice($scope.items.indexOf(item), 1);
}
});
<div ng-controller="MyCtrl">
<div ng-repeat="item in items | orderBy: 'id'" ng-click="delete(item)">
<span>
Hello, {{item.name}}!
</span>
</div>
<input type="text" ng-model="items" />
</div>
<script src="https://code.angularjs.org/1.4.0/angular.js"></script>
To view the JSFIDDLE demonstration, click here.
$scope.delete = function (item) {
$scope.items.splice($scope.items.indexOf(item), 1);
}