Using the model's value as the name for another model in AngularJS

var app = angular.module('LoginApp',[]);

app.controller('dynamicController', ['$scope', function($scope) {
   $scope.role= "Admin";

   $scope.auctionNumber = 1;

   $scope.itemsArray = [{ letter:"a" , number:1 }];
}]);

To display the model name in HTML, use {{ variable }} and set it to be {{ itemsArray.letter }}_{{ auctionNumber }}. This will result in displaying Admin.

Answer №1

To access the value, you can utilize the bracket notation

$scope[$scope.item[0].A + "_" + $scope.auction_no]

Answer №2

If you set your initial variable as an object:

$scope.auctions = {
  a_1: 'Admin'
};

$scope.auction_no = 1;
$scope.item = [{ A:"a" , B:1 }];

var result = $scope.auctions[$scope.item[0]['A'] + '_' + $scope.auction_no];

At this stage, the variable result will contain the value Admin.

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

Obtaining varied outcomes while printing filtered information

As a beginner in React.js using hooks, I prefer to learn through hands-on coding. My query revolves around fetching data from a specific URL like ksngfr.com/something.txt and displaying it as shown in the provided image (I only displayed numbers 1-4, but t ...

Accessing the AppContext in Next.js within the _document file is the

My challenge with using next js is the occurrence of Content-Security-Policy issues due to the inline styles it utilizes. If 'unsafe-inline' is not added to the style-src, you will encounter the error message 'Refused to apply inline style ...

Angular JS Profile Grid: Discover the power of Angular JS

I came across an interesting example that caught my attention: http://www.bootply.com/fzLrwL73pd This particular example utilizes the randomUser API to generate random user data and images. I would like to create something similar, but with manually ente ...

A guide on adjusting a function to pause execution until a line is complete

In the code snippet below, there is an angularJS function named myFunc: $scope.myFunc = () => { myModule.getConfig().update(params); myModule.go(); myModule.log('ok'); }; Additionally, there is a go function defi ...

"Troubleshooting the issue of ng-init not functioning properly in conjunction

I need help with displaying a list of numbers inside a div element. I am attempting to achieve this using the following code snippet: <div ng-init="range=[1,10,3,4,5]" ng-repeat="n in range" > {{n}} </div> Unfortunately, the numbers withi ...

Can you explain the distinction between window.location.hash and just location.hash?

In many Javascript scripts, I frequently come across mentions of window.location.hash and location.hash (using "hash" as an example). Can someone explain the distinction between these two calls, as they appear to produce the same outcome to me? ...

Tips for customizing a dropdown menu where the first item is not the label and may include an input field

How can I create a dropdown box that includes a label of "select so and so..." and when the user clicks on it, a list of options is displayed with the first option being blank instead of showing the label name? Is it possible to include an input box insi ...

The form tag is failing to display the Name input field

Currently, I am facing an issue with the form tag rendering like this: <form method="post" action="AdminEditListTest.aspx" id="Form1" name="Form1"> This piece of code is considered as legacy and relies on document.Form1.XXX for DOM manipulation o ...

Discovering the Coordinates of document.DocumentElement.ClientWould you like to know how to

Using document.documentElement.clientWidth and document.documentElement.clientHeight, I can determine the width and height of a browser page. My next query is regarding the coordinates of the top left and top right corners of the client viewport. Is there ...

Exploring new ways to add line breaks in Angular UI drop-down boxes

Hello everyone, I'm having an issue with the drop-down toggle feature in ui.bootstrap. Instead of aligning properly in my menubar, it's creating a new line. I've set up a plunker to demonstrate the problem. You can see that when I insert a ...

How to transfer a parameter in Angular 2

I am currently facing a challenge in passing a value from the HTML file to my component and then incorporating it into my JSON feed URL. While I have successfully transferred the value to the component and displayed it in the HTML file, I am struggling to ...

Navigate to an element with a specific ID using JavaScript

How can I implement scrolling to an element on a webpage using pure javascript in VueJS with Vuetify framework? I want to achieve the same functionality as <a href="#link"></a> but without using jQuery. My navigation structure is as follows: ...

Can someone help me uncover the previous URL for login using just JavaScript? I've tried using document.referrer but it's not giving me the

Currently, I am utilizing express with pug templates and pure JavaScript. In order to enhance the user experience of my log in system, I would like to save the URL that someone came to the login page with, so that I can redirect them back to it once they h ...

I was able to resolve the display block issue, but I suspect there might be a mistake in my conditional statement

Looking for some help here - I want my user prompts to be displayed in block form, while the user story and error messages should remain hidden until the user enters their inputs. However, my script seems to be malfunctioning and I can't figure out wh ...

Comparing Ajax methods: Which one reigns supreme?

I am seeking advice on the best approach to handle a series of Ajax insert, update, and delete operations. Which method is more effective? Creating individual methods for each function (e.g., delete_foo, insert_foo, update_foo, delete_bar, insert_bar, ...

After deployment, AngularJS is failing to function

My AngularJS module is not functioning properly after being deployed on IIS 8.5. The code works perfectly fine on my local machine with Visual Studio 2012. angular.module('MyApp').controller("DataViewController", ["$scope", "RequestService", fun ...

Setting the mesh size to perfectly match the viewport height and screen dimensions in three.js - here's how!

Check out this Codesandbox demo for a canvas lighting experiment: https://codesandbox.io/s/canvas-lighting-experiment-wip-3p9im?file=/src/Canvas.component.jsx Although I've adjusted the canvas to fit the height and width of the window, the mesh withi ...

Display jade template with parameters that are bound using angular during rendering

Whenever I receive a request, I use a jade template and pass specific parameters to it. res.render("result.jade",{order_id: "abc123"}); I am looking for the most effective method to bind these passed parameters to scope variables when they are rendered o ...

The display of the Ajax response is not appearing on the page

Here is my AJAX code: $.ajax({ type: 'POST', url: ajax.ajax, contentType: false, processData: false, dataType: 'JSON', status: 200, data: formdata, success: function(m ...

Determining the Width of a DIV Dynamically with CSS or LESS Depending on the Number of Siblings

One of my challenges involves a parent DIV with a width set to 100%. Dynamically, this parent DIV is filled with numerous children DIVs. I am trying to calculate and assign their widths using only the calc method in CSS or LESS. This is because the flex ...