Link the input value to the attributes of an object

Can someone guide me on how to connect input values to an object? TypeScript-file:

private shareholder = { 
shares : 'value from input'
name:  'value from input'
}

Here is the corresponding HTML code:

<input name="shares" ng-model="shares"  type="number" required>
<input name="name" ng-model="name" required>

Answer №1

Suppose you have an object named `shareholder` in your 'myController', here's what you can do:

<div ng-controller="myController as $ctrl">

    <input name="shares" ng-model="$ctrl.shareholder.shares"  type="number" required />
    <input name="name" ng-model="$ctrl.shareholder.name" required />

</div>

Remember to make your `shareholder` object `public` if accessed outside the controller.


If you are using `$scope`, here is how you can handle it:

$scope.shareholder = { 
    shares: 'value from input'
    name: 'value from input'
}

In the view, you will use:

<input name="shares" ng-model="shareholder.shares"  type="number" required />
<input name="name" ng-model="shareholder.name" required />

Answer №2

Control System

let investor = { 
investment: 'retrieve value from form input',
person:  'retrieve value from form input'
} 

HTML Structure

<input name="investment" ng-model="investor.investment" type="number" required>
<input name="person" ng-model="investor.person" required>

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

Leveraging interfaces with the logical OR operator

Imagine a scenario where we have a slider component with an Input that can accept either Products or Teasers. public productsWithTeasers: (Product | Teaser)[]; When attempting to iterate through this array, an error is thrown in VS Code. <div *ngFor= ...

Generating a dynamic SQL Update statement using an array of objects

I am currently working with an array of objects in order to create an Update SQL statement. Here is the array I am using: let dataUpdate = [ { "field1":123, "field2":"BMW", "field3":"blue" ...

Dayjs is failing to retrieve the current system time

Hey everyone, I'm facing an issue with using Dayjs() and format to retrieve the current time in a specific format while running my Cypress tests. Despite using the correct code, I keep getting an old timestamp as the output: const presentDateTime = da ...

Executing a series of sequential HTTP calls in Angular can be achieved by chaining

Is there a way to create a function that can make HTTP calls one after the other, allowing me to use the response from the first call in the second call? For example, retrieving the user's IP address from the first call and then using that IP address ...

Acquire the top-scoring item using React

I retrieved data from the backend Below is the code snippet where I display the data: <div className="pr-0 mt-20" style={{ display: 'flex', justifyContent: 'center' }}> <MuiCardWithAnimation component={AnimateS ...

Emphasize the ng-repeat item upon clicking the Google Maps marker

Take a look at this demo where I am trying to highlight ng-repeat elements when the corresponding google map marker on the map is clicked. The highlighting currently works when clicking the ng-repeat element, but not when clicking the marker. Here is the ...

Using the indexOf method to arrange the data in the desired order

Greetings to all! Currently, I am working on implementing Angular fusion chart. My objective is to populate the data based on the product (json data) available. However, I am encountering an issue while utilizing the indexOf method in my fusion chart. All ...

Encountering issues transferring form data from a SvelteKit server endpoint to formsubmit.co/ajax

Currently, I am developing a SvelteKit project that requires sending form data from a server endpoint to an external API called FormSubmit.co/ajax. While I can successfully send the form data directly from the client-side in a +page.svelte file, I have enc ...

The implementation of CommonJS modules allows for efficient modularization

While using Nx for my Angular workspace, I noticed something that sparked a question in my mind. Why is it necessary to use CommonJS modules in all tsconfig.spec.json files for libs? Looking at Nx examples, I observed that not all libs include it, only app ...

Newly created item not showing up in Bootstrap carousel

Incorporating a bootstrap carousel with ng-repeat into my div has been quite the journey. One challenge I've encountered is adding new items to the current list and smoothly transitioning to that newly added item. For instance, when I am at index 0 a ...

Having issues with an AngularJS test in Protractor where the Jasmine spec seems to be timing out on the 'expect' clause. Could resetting the WebDriver Control Flow help?

Currently in the process of creating a series of tests using Protractor to validate an AngularJS application that my company is working on. While running through the tests, I encountered a failure with one of them and couldn't determine the root cause ...

Integrating Immutable.js with Angular 2

Looking to optimize performance in your Angular 2 app with immutable.js? Although my app is functioning properly, I am aiming to enhance its performance through optimization and refactoring. I recently discovered immutable.js and want to convert the data ...

`Grab the attention of a specific span of text using AngularJS`

What I have is a code that currently highlights words in a list based on a predefined array. $scope.arrayFilter=["is","mom","beautifull",'beer']; However, I no longer need this code. I only want to highlight text within the ".marque" class from ...

Filtering database results from an Angular component

I am currently working on an Angular component and I have a result variable in the .ts file that stores data retrieved from the database. My goal is to filter this result variable to display only 20 records and sort them by date either in ascending or de ...

Guide on deactivating the div in angular using ngClass based on a boolean value

displayData = [ { status: 'CLOSED', ack: false }, { status: 'ESCALATED', ack: false }, { status: 'ACK', ack: false }, { status: 'ACK', ack: true }, { status: 'NEW', ack ...

AngularJS, encountering issues with resolving an unknown provider

I have set up two routes with resolve as shown below: .when('/foos', { templateUrl: 'views/foos.html', controller: 'FoosCtrl', resolve: { foo_list: ['$q', '$route', '$timeout', '$locatio ...

Unable to access complete map using ngmap and AngularJS

I am currently working with ngmap and encountered the issue shown in this screenshot https://i.stack.imgur.com/WchKT.png Here is my code: var app = angular.module('dv', ['ngMap']) app.controller('MC', function($scope){ ...

Incorrect errors are displayed by VS Code in ts-node shell scripts

I came across an interesting article discussing running a TypeScript file on the command line, and while it seems to be functioning properly, I am encountering invalid errors in VS Code: https://i.sstatic.net/eis3X.png As seen in the terminal (bottom hal ...

AngularJS Service that handles several independent queries

I'm struggling with creating an AngularJS service that fetches data from multiple HTTP requests. Despite my efforts, I can't seem to get it working. The REST call flow is as follows: Get /index which returns an array of URLs Call each URL and ...

Ways to encourage children to adopt a specific trait

Let's discuss a scenario where I have a React functional component like this: const Test = (props: { children: React.ReactElement<{ slot: "content" }> }) => { return <></> } When a child is passed without a sl ...