unable to push string to listbox in angularjs

75 Views Asked by At

When I'm trying to push a string(New) to a list box it was inserting as "undefined" to it.

  $http({
            method: 'GET',
            url: 'http://xxx/api/Maintenance/GetAllFilteredItems',
            params: { Pt_Id: PtId}
        }).then(function successCallback(response) {
            $scope.items = response.data;         
        }, function errorCallback(response) {
            // alert(response);
        });



 $scope.AddNew = function () {
     var Item = [];
        Item[0] = 'New'; alert(Item.length); 
      //  $scope.items.splice(0, 0, Item[0].toString());
        $scope.items.splice(0, 0, Item[0]);
        //  $scope.items.push($scope.input);
        //  $scope.items.splice(0, 0, { itm: 'New'});
        $scope.itm = $scope.items[0];     


        //var item = new String('New')
        //$scope.items.splice(0, 0, item);
        //$scope.items.unshift(item);
}

Tried in different ways as above but no luck.

1

There are 1 best solutions below

0
user2522503 On BEST ANSWER

Hope the items were in $scope.items are objects and you're trying to insert a string to that listbox so it was inserting as undefined.

Try to push that items like below to listbox then you can push any string which you want.

public List yourmethod() {....} // to $scope.items