Is it possible to integrate ng-repeat with ng-model in Angular?

Is it possible to link the ng-model of a button with the ng-repeat loop?

<a ng-repeat="x in [1,2,3,4]" ng-model="myButton[x]">{{myButton[x]}}</a>

In the Controller:

var id = 4;
$scope.myButton[id] = ' :( ';

I am interested in creating a variable that incorporates external values. Any suggestions on how to approach this concept more efficiently would be greatly appreciated as I feel like my current method might not be the most optimal solution.

Answer №1

Is this what you're looking for?

HTML:

<div ng-app="myApp" ng-controller="myCtrl"> 
    <a ng-repeat="x in [1,2,3,4]" >{{myButton[x]}}</a>
</div>

JS:

var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) { 

    var first = 1, forth = 4;
    $scope.myButton = [];
    $scope.myButton[first] = ' 1st ';
    $scope.myButton[forth] = ' 4th ';
    $scope.myButton[5] = ' 5th ';
});

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

Creating a diverse layout by dynamically adding divs without achieving uniformity in the grid

I'm working on dynamically generating a grid of divs with a specific size using the code below: function createGrid(gridSize) { var container = document.getElementById('container'); for (var i = 0; i < gridSize; i++) { va ...

skip every nth element in the array based on the specified value

The Challenge I'm currently working on a graph that relies on an array of data points to construct itself. One major issue I've encountered is the need for the graph to be resizable, which leads to the necessity of removing certain data points ...

Checking the Ajax request with an if statement

$("#Submit").click(function(event){ event.preventDefault(); var th = '<tr><th>' + "Business" +'</th><th>' + "Address"+ '</th><th>'+ "Rating" + '</th><th>' + "Da ...

Error: Discord bot encountered a TypeError while attempting to access the property 'id' of an undefined value

After revisiting a previous Discord bot package designed to track website updates, I encountered an issue. The code was originally scraped and last edited about 8 months ago with success. However, upon running node index.js, the following error occurred. ...

Adjust the node_modules path tailored to your project

My current project structure looks like this: |-app |-... |-libs |- package.json |- index.html I am interested in organizing my project such that the 'node_modules' folder is inside the 'libs' folder. The desired structure is as fo ...

Clicks on jQuery buttons

I recently experimented with jQuery and AngularJS by creating a simple app that includes index.html, first.html, second.html, third.html, and fourth.html. Each subpage features a button that changes the background-color when clicked. When it comes to the ...

Receiving constant errors on Search Input in React: continuously encountering the error "Cannot read property 'value' of undefined."

Attempting to incorporate the < ChipInput /> element from https://github.com/TeamWertarbyte/material-ui-chip-input. Using material-UI react component, my current setup includes: A functional search input bar. When an artist's name is typed, it ...

What is the method for acquiring a dynamic segment in the router of a Next.js 13 application?

Currently in my project, I am using the new App Router in Next.js 13 and MongoDB as the DBMS to fetch data via API. When trying to retrieve all data from a collection, it is successful. However, fetching only one data results in failure. The error message ...

What is the best way to include a variable or literal as a value in styled components?

When it comes to managing various use cases, I always rely on props. However, I am currently facing a challenge in changing the border color of a styled input during its focus state. Is there a way to utilize props for this specific scenario? Despite my f ...

Instructions on how to toggle the visibility of a div when hovering over a different a tag

To keep things simple, I'm looking to create a visibility toggle effect on a div when someone hovers over an anchor tag. Similar to the behavior of the four buttons on this example link: The issue I'm facing is that I want the div to appear or b ...

Finding the initial occurrence of duplicates within an array of objects using JavaScript

I am working with a data structure retrieved from an API, and it looks like this: [ { id: '10000844', text_id: '10000844-01', }, { id: '10000844', text_id: '10000844-02', }, { id: ' ...

What is the best way to transfer data from a custom method and use it in another method within my constructor function in Javascript?

As I pondered a suitable example, I devised a constructor function centered around precious metals. This function accepts the type of metal and its weight as parameters. Within this constructor, there are two methods: one to verify if the precious metal (g ...

Looking to tilt text at an angle inside a box? CSS can help achieve that effect!

Hey there, is it possible to achieve this with CSS or JavaScript? I require it for a Birt report. ...

Getting the id of a row from a v-data-table in VueJs

I am currently facing an issue with retrieving the id of a specific field from each row. I require this id as a parameter for a function that will be utilized in an action button to delete the row. Here is how my table template appears: <template ...

Where can I locate the Socket.IO server within the local area network (LAN)?

I am currently in the process of developing an application that facilitates connections between devices within the same network. In my design, any device can act as a server, and I aim for clients to automatically detect the server without requiring users ...

Not including the Spring annotation @ResponseBody can result in a 404 error

When I do not include @ResponseBody in my service, it results in a 404 error even though the service is successfully called. In the logs, I see this exception being thrown: .10:00:38.716 [http-nio-8082-exec-10] WARN o.s.web.servlet.PageNotFound - No ma ...

Utilize AxiosAbstraction to transmit a Patch request from a Vue.js application to a PHP backend

I need help with sending a PATCH request to update the birthdate of a user (promotor) from Vue.js frontend to PHP backend. The issue I'm facing is that the new date of birth is not getting saved in the database, and the existing date of birth in the d ...

AngularJS - Determine the correct condition or make a choice from the available options

I'm having trouble figuring out how to save the option I select to a viewmodel. The ng-model should save whatever option I choose, and if nothing is selected, the value should default to "Select One." The available options are YES (true) / NO (false). ...

Aligning the title vertically in Ionic on Android device

Currently, I am in the process of developing an application using the Ionic framework and cordova. After uploading my app for testing purposes, I encountered a small issue. The title in the top bar on Android appears to be misaligned vertically. Is there a ...

What is the reason behind the malfunctioning of the custom directive?

I've been working on creating my own custom directive in AngularJS. Here's an example of what the code looks like: <!DOCTYPE html> <html lang='en' ng-app='testApp'> <head> <meta charset=&apos ...