无法将字符串推送到angularjs中的列表框

问题描述 投票:0回答:1

当我试图将一个字符串(New)推送到列表框时,它将“未定义”插入其中。

  $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);
}

以上述不同的方式尝试但没有运气。

javascript angularjs angularjs-scope angularjs-select
1个回答
0
投票

希望项目在$ scope.items中是对象,并且您正在尝试将字符串插入该列表框,因此它插入为未定义。

尝试将下面的项目推送到列表框然后您可以推送任何您想要的字符串。

public将yourmethod(){....} //列入$ scope.items

© www.soinside.com 2019 - 2024. All rights reserved.