0

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 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.