Encountering an issue when trying to assign a database value to a drop-down list using Angular.js

I encountered an issue while attempting to set the database value using Angular.js.

Error:

TypeError: index.push is not a function

Below, I have provided an explanation of my code.

<tr ng-repeat="d in days">
<td>{{d.day}}</td>
<td> <select class="form-control"  id="catagory" ng-model="catagory" ng-options="cat.name for cat in listOfCatagory track by cat.value " ng-change="removeBorder('catagory',$index,catagory.value);" >
 </select></td>
<td>
<select class="form-control"  id="subcatagory+$index" ng-model="subcatagory[$index]" ng-options="sub.name for sub in listOfSubCatagory+$index track by sub.value " >
<option value="">Select Subcategory</option>
</select>

</td>
<td><input type="text" name="comment" id="comment" class="form-control oditek-form" placeholder="Add Comment" ng-model="comment" ng-keypress="clearField('comment');"></td>
</tr>

When the user selects a value from the first drop-down list, the following part of the code executes.

$scope.removeBorder=function(id,index,catvalue){
        var catdata=$.param({'action':'subcat','cat_id':catvalue});
        $http({
            method:'POST',
            url:"php/customerInfo.php",
            data:catdata,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function successCallback(response){
            //console.log('sub',response.data);
            angular.forEach(response.data,function(obj){
                var data={'name':obj.subcat_name,'value':obj.subcat_id};
                $scope.listOfSubCatagory+index.push(data);
            })
        },function errorCallback(response) {
        })
    }

I am encountering an error with this line of code:

$scope.listOfSubCatagory+index.push(data);
. Any assistance in resolving this error would be greatly appreciated.

Answer №1

Utilizing the ng-change="removeBorder('category',$index,category.value);"

The value of $index corresponds to the position of the element in the array, and it is represented as an integer.

Attempting to use the .push() function on an integer is causing the error you are experiencing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to run a query in PHP that executes successfully in phpMyAdmin

I'm currently attempting to remove rows from a table using the following code: $query = "Delete from usertour where tourID = $idnum and name LIKE '%$session%' "; However, even when the idnum and session are correct, the row is not being ...

The Google Classroom share button is failing to display

I'm trying to incorporate a Share to Google Classroom button into my AngularJS app, but I'm having trouble getting it to render. Has anyone else encountered this issue and found a solution? I've added the following script to my index.html fi ...

Having trouble retrieving multiple selected values from the paper listbox in Polymer 3

I'm attempting to retrieve multiple selected values in a paper-listbox element in Polymer. <paper-dropdown-menu label="{{_getLabel('Activity Type')}}" id="fromMenu" on-paper-dropdown-close="fromAccountChanged" searchable="true"> ...

Add the file to the current directory

As a newer Angular developer, I am embarking on the task of creating a web page that enables users to upload files, with the intention of storing them in a specific folder within the working directory. The current location of the upload page component is ...

What is the reason for HTML Entity not functioning in the input title for React?

Can someone explain why I am unable to use the HTML Entity &le; in the HTML input title attribute when using a JavaScript constant, but it works fine with a string? The HTML Entity &le; represents the ≤ symbol. To demonstrate this issue, please ...

What purpose does generating a JSON file serve when invoking getStaticProps in Next.js?

Just diving into the world of Next.js. I've been going through the Next.js documentation and stumbled upon this: Next.js creates a JSON file that contains the outcome of executing getStaticProps. This JSON file is used in client-side routing via nex ...

Dealing with multiple jQuery ajax requests - strategies for managing them

Whenever I click the button quickly while there is jQuery Ajax loading, it seems to get stuck. How can I manage multiple requests being fired at the same time? What is the solution for the following: Cancel/abort all previous requests and only handle th ...

Tips for sending AJAX POST requests to PHP servers

I've been struggling to grasp how to effectively use ajax for posting data. Despite simplifying my form down to just two values, I still can't seem to get it to work. Here's my HTML code: <html> <head> <script type="text/java ...

Utilizing a service to access directive scope within a controller

I attempted to retrieve a value returned by a directive within my controller using a service. However, I encountered an issue where it seems like the updated return value from the directive is not being captured by the controller. Below is the code snippe ...

Implementing a Dropdown Menu Within a React Form

I am currently working on setting up a reservation system for rooms. I want to include 2-4 different room types and incorporate a dropdown menu instead of manual input. I am using the guidance provided here. I attempted to use <Form.Select...>, but i ...

Prevent selection of future dates in JavaScript by using the user's chosen StartDate

Here is the code I currently have: var today = new Date().toISOString().split('T')[0]; document.getElementsByName("StartDate")[0].setAttribute('min', today); $('#StartDate').change(function myfunction() { var endDate = ...

After the form is successfully submitted, you can remove the required attribute

Upon clicking the submit button of a form, an input box is highlighted with a red border if empty. After successful jQuery AJAX form submission, a message "data submitted" is displayed and the form is reset causing all input fields to be highlighted in red ...

Tips on updating the $authProvider.loginUrl for Satellizer from an Angular controller

Consider this hypothetical situation: A user attempts to access a /settings page without being logged in. The Settings controller detects based on $auth.isAuthenticated() != true that the user is not logged in, and directs them to the /login page. The us ...

What issue is being encountered with this JavaScript generated by PHP?

PHP on the host generates JavaScript code that results in an error stating: missing ; before statement The generated JavaScript code looks like this: try{ obj = document.getElementById('subcat'); }catch(e){} try{ obj.innerHTML = ...

Attempting to integrate a TypeScript library with a JavaScript Express application

I have been attempting to integrate a TypeScript library like this into an existing Express Node.js application, but unfortunately it is not working as expected. Upon importing the library functions, I keep encountering errors such as "Cannot read property ...

What is the best way to merge all project modules into a single file using the r.js optimizer?

While working with the r.js optimizer, I noticed that the final index.html file doesn't seem to allow for referencing just a single script without making any async calls to other scripts during a user's session. It appears to generate multiple gr ...

The drop-down component is being filled with data but unfortunately, only dummy data is functional at the

Having trouble populating data in the drop-down component. Everything works fine when using dummy JSON data as shown in the comments. The GET request service retrieves the necessary data, and then I assign the response to the appropriate variable. The GET ...

What is the correct method for notifying the progress of time using jQuery?

I'm looking for a way to display the processing time of my PHP code using jQuery Here's an example of my PHP code : <?php //some queries to database ?> Below is my jQuery code: $.ajax({ type: "POST", url: "action. ...

Troubleshooting CSS override issues when swapping components in ReactJS

Access.js import React from 'react' export default class Access extends React.Component { componentWillMount(){ import ('./styles/access_page.css'); } .... <Link to="/new-account">Sign Up</Link> } Cr ...

Is JavaScript asynchronous when it comes to manipulating the DOM?

While conducting Javascript tests on the Android browser, I monitored the number of instruction counts executed on the CPU. The test code for JS is straightforward and embedded within HTML files located in the local directory of an Android device, not on a ...