Access information from an array in Angularjs and transfer it to an identifier

I am facing an issue with passing values from the view to the controller and storing them in an array. My goal is to then retrieve a value from the array and pass it as the id value in the update method.

Here is my current setup:

HTML

<label class="control-label col-xs-8 col-sm-3 no-padding-right" >Choose a Plate</label>
            <div class="col-xs-12 col-sm-9">

                <select id="plateId" ng-model="selectedPlate" ng-options="plate as (plate.wafer_id + ' - ' + plate.serial_number) for plate in plates" ng-change="getSelectedPlateID(selectedPlate)"/>
                    <option value="">Select</option>



                </select>

And this is my controller

$scope.plateid = [];

$scope.inspectionData = {
    equipment_status_codes_id: 1,
    plate_container_id: 1,
    plate_container_slot: 21,
    plate_quality_id: 1
}

PlatesFactory.query(function(plates)
{
    $scope.plates = plates;
});

$scope.getSelectedPlateID = function(item)
{
    $scope.plateid.push({
        plate_id : item.id
    });

    console.log($scope.plateid[0]);

}

PlatesInspectionFactory.update({id : $scope.plateid[0]}, $scope.inspectionData)

Someone suggested using

{id : $scope.plateid[0].plate_id, 

but unfortunately, this didn't work for me.

I've been stuck on this problem for a day or two now. Can someone please help?

Answer №1

You're encountering an issue where values are being pushed to an object and accessed incorrectly. To further illustrate this problem, I've put together a demonstration in a fiddle: http://jsfiddle.net/zy78PqkW/7/

Here's a suggested solution:

$scope.plateid = [];

$scope.inspectionData = {
    equipment_status_codes_id: 2,
    plate_container_id: 2,
    plate_container_slot: 31,
    plate_quality_id: 2
}

PlatesFactory.query(function(plates) {
    $scope.plates = plates;
});

$scope.getSelectedPlateID = function(item) {
    $scope.plateid.push({
        plate_id: item.id
    });

    console.log($scope.plateid[0]);
    //alert(item.wafer_id)
}

// The current update is not functioning as expected, the object isn't updating on the database

PlatesInspectionFactory.update({ id: $scope.plateid[0].plate_id }, $scope.inspectionData)

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

The attributes `ng-class` and `class` are used to apply CSS styles

Can you provide guidance on when to use one method over the other for HTML elements such as div, span, and tables? Is it advisable to mix both methods or could it potentially cause some issues? ...

After attempting to install @mui/system, I encountered an error. I decided to uninstall it, but now I am consistently facing this

ERROR in ./node_modules/@mui/material/Unstable_Grid2/Grid2.js 6:14-25 export 'createGrid' (imported as 'createGrid2') was not found in '@mui/system/Unstable_Grid' (module has no exports). Encountering an issue after installin ...

What is the best way to update your XML array using your Java file in an Android application?

I am working with an array of Strings named "athlete_array", containing one item. However, I would like to add more items to this array using a java file called CreateTeamActivity. Is it possible to create a method within the CreateTeamActivity class to ...

Exploring mongoDB with the "find" query

I am encountering an issue with my MongoDB database. Here is the structure of the data: { "_id" : ObjectId("585fe33d3c63b4a81e00002b"), "class" : [ { "name" : "class 1", "people" : [ { "id" : "58596", ...

I'm looking for a way to showcase JSON data retrieved from the controller using AngularJS

I am looking to utilize AngularJS in my view to display JSON-encoded data retrieved from the controller. <div ng-app="memberApp" ng-controller="memberCtrl"> <input type="text" ng-model="search" />Search <table class="table table-bor ...

When utilizing the React API Fetch, there may be instances where not all data is returned. However

Having some trouble with my FetchData class. I am receiving a list of data, but it's in an array format. When I try to access specific values like countries: data.Countries[0], I can get individual values based on the index. However, what I really wan ...

Unleashing the Power of Object Destructuring in React Hooks

Here is a straightforward code snippet: import React from "react"; import { useForm } from "react-hook-form"; export default function App() { const { register, formState: { errors }, handleSubmit } = useForm(); return ( < ...

Guide on combining two JSON Array objects in Nodejs

Is there a way to merge two JSON Array objects together using Node.js? I am looking to combine obj1 + obj2 in order to create a new JSON object: obj1 = [ { t: 1, d: 'AAA', v: 'yes' }, { t: 2, d: 'BBB', v: 'yes& ...

Guide on how to design a schema in Mongoose for uploading arrays of objects in MongoDB

[ const arrayOfObjectsSchema = new Schema({ array: [ { title: { type: String, required: true, }, desc: { type: String, required: true, }, img: { type: String, required: tru ...

When choosing from multiple dropdown menus, the selected option should be hidden from the other dropdowns

I'm currently working on a project that involves designing a web form incorporating 3 select boxes with multiple questions. The concept is such that, if I choose the 1st Question from the 1st select drop-down, it should not be available in the 2nd sel ...

Login and session management for users using AngularJS in the client-side and Spring in the backend

Currently, my mobile website is built using angularjs, and the backend is powered by Spring Boot. The issue I am facing is that when a user logs in successfully, their information is obtained from the server, but if they click "back" or "refresh" on the br ...

Node and Socket.IO - Personalized messaging (one-on-one)

I'm in the process of developing a one-on-one chat feature using Socket.IO and Express to enable private messaging between users. The main issue at hand is: I am looking for a way to send a private message to a specific socket.id while ensuring that ...

RegEx unable to extract a number ranging from 0 to 23

Can you figure out why this JavaScript regex is having trouble parsing a number between 0 and 23? pattern = /([0-1]?[0-9]|2[0-3])/ "12".match(pattern) // => matches 12 "23".match(pattern) // => matches 2 (should match 23) ...

Can you define the "tab location" in an HTML document using React?

Consider this component I have: https://i.stack.imgur.com/rAeHZ.png React.createClass({ getInitialState: function() { return {pg: 0}; }, nextPage: function(){ this.setState({ pg: this.state.pg+1} ) }, rend ...

The curly braces in AngularJS are failing to display the values on the HTML page

After trying various articles and solutions to different questions, I am still unable to resolve my issue. I am working on a blank ionic project and it is running smoothly in my browser using ionic serve without any errors. However, instead of displaying ...

What changes can be made to the HTML structure to ensure that two form tags function separately?

Hey there! I'm currently tackling a web project that involves incorporating two form tags on one page, each with its own distinct purpose. Nevertheless, it appears that the inner form tag isn't behaving as it should. My suspicion is that this iss ...

Implementing a separate detail view in Vuejs

I am currently working on a page with multiple cases. When I click on a case, the details for that case appear on the same page. Here is a screenshot of how it looks: https://i.sstatic.net/Y9S4J.png As you can see in the screenshot, there are two cases li ...

Error message: 'Unsupported projection operation: $push: { ... }', error code: 2, code name: 'InvalidOperation' }

Can anyone assist me with debugging this error that I am encountering? Here is the code snippet causing the issue: router.post('/accounts/show_accounts/:id', function(req,res){ Account.findOne( {_id:req.params.id}, {$push: { ...

Function in head not triggering on OnMouseOver event

My goal is to have specific text display on my page when a user hovers over an image, with the text changing for each image. Below is the code snippet for the header section: <head> <title>Indian Spices Page</title> <link rel="s ...

Is it possible for me to input a variable into the logical process of if(isset($_FILES['whatever']))?

I have recently started learning PHP and I'm in the process of creating a dynamic page that will update based on which form buttons are clicked. The functionality is working correctly, but my goal is to enable users to upload multiple files - either P ...