Ad
Unable To Push String To Listbox In Angularjs
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.
Ad
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
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad