Ways to showcase title using ng-repeat

<input type="text" ng-model= "name" title="{{name}}">
//this title displays the name that is contained in ng-model

Similarly...

<select title ="{{item.actionId}}" ng-model="item.actionId"> 
<option ng-repeat="action in actionList" value="{{action.ACTION_ID}}">{{action.URL}}</option>
</select>

List of Actions:

$scope.actionList = [{
    "ACTION_ID": 39,
    "URL": "/abc"
  }, {
    "ACTION_ID": 59,
    "URL": "/xyz"
  }];

In this case, item represents the parent list. The title displayed is its ID as the value is the ID. However, we want to retrieve the corresponding URL. How can we do that?

Answer №1

The JSON data and code appear to be correct. Feel free to refer to the demo below if you need any further assistance.

DEMO

var app = angular.module('myApp', []);
app.controller('AppCtrl', function($scope) {
 $scope.actionList = [{
    "ACTION_ID": 39,
    "URL": "/abc"
  }, {
    "ACTION_ID": 59,
    "URL": "/xyz"
  }];
});
<!DOCTYPE html>
<html>
<head> 
</head>

<body>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
 <div ng-app="myApp" ng-controller="AppCtrl">
  <div class="form-group">
    <select title="{{item.actionId}}" ng-model="item.actionId"> 
<option ng-repeat="action in actionList" value="{{action.ACTION_ID}}">{{action.URL}}</option>
</select>
</div>
 </div>
</body>

</html>

Answer №2

You can implement ng-options in conjunction with ng-change to record the ids and display the URL in the title

var app = angular.module('app', []);
app.controller('Ctrl', function($scope) {
 $scope.actionList = [{
    "ACTION_ID": 39,
    "URL": "/abc"
  }, {
    "ACTION_ID": 59,
    "URL": "/xyz"
  }];
  $scope.getValues=function(){
  debugger
    $scope.selectedID=$scope.item.ACTION_ID;
    $scope.selectedURL=$scope.item.URL;
    console.log("selectedId:" + $scope.selectedID );
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head> 
</head>

<body>
 <div ng-app="app" ng-controller="Ctrl">
  <div class="form-group">
    <select ng-model="item" ng-change="getValues()" ng-options="action as  action.URL for action in actionList" title="{{selectedURL}}"> 
</select>
</div>
 </div>
</body>

</html>

Answer №3

If you want to achieve this, you can use the following code snippet:

<select ng-model="item" ng-options="action as action.URL for action in 
 actionList" title="{{item.URL}}"> 

Answer №4

It is recommended to utilize ng-option instead of ng-repeat. Also, make sure to always incorporate the track by clause to assign a value in the option list when generating it from an object.

<!DOCTYPE html>
<html>
<body>

<select ng-model="item" ng-options="action as action.URL for action in actionList track by action.URL" >
  <option value="">Volvo</option>
     </select>

</body>
</html>

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

Watching the $scope variable using $watch will result in triggering even when ng-if directive is used, displaying

Encountering an unusual behavior in AngularJS that may appear to be a bug, but there could be a logical explanation. A certain value is being passed to a directive as an attribute. Within this directive, the parameter is being watched using $scope.$watch. ...

Assign the value of the selected option to the ng-model instead of the displayed text

When creating a new user, I am collecting user input. Users have the option to select their state from a dropdown menu. I am looking to save the state ID instead of the state name when the user makes a selection. How can I assign the state ID to the newSit ...

Having trouble loading an image after successfully connecting to an API with react.js

I've been working on a custom fetch component to load images from the "the dog API" onto my page. However, I'm facing some issues with getting the images to display correctly. Can anyone spot what might be missing in my setup? App.js import &apo ...

Having trouble getting the JavaScript slider to animate

My code works perfectly in Codepen but when I try to implement it on my website, it shows as a static image. You can view the code here: https://codepen.io/anon/pen/zPMKpv I'm using the exact same code on my website located at: Does anyone have any ...

Importing D3 data from CSV files using the "%" symbol

I am trying to import a CSV file with the following data: Month, Ratio January, 0.19% February, 0.19% March, 0.19% April, 0.18% The current code snippet I'm using is as follows: d3.csv("month_ct.csv", function(d) { return { month: d ...

Setting the default selection in AngularJS based on the URL entered

I've encountered an issue with a dropdown menu in my AngularJS version 1.4 application. The dropdown menu contains links to different sections of the page. The problem arises when I directly enter the page URL - instead of selecting the correct link f ...

What is the most effective way to receive all values sent to an Observer upon a new subscription?

I have an observer that receives various values emitted to it at different times. For instance sub = new Subject<any>(); sub.next(1); sub.next(2); sub.next(3); #hack 1 sub.next(4); sub.next(5); sub.next(6); #hack 2 If there is a ...

Can you provide me with information on how to retrieve data from a Yahoo Finance JSON file using Node.js?

I have created a simple request function to fetch JSON data from the Yahoo Finance API, but I am encountering difficulties in extracting information from the JSON response. Here is my code: var request = require("request"); var stock_url = "http://finan ...

Tips on successfully passing multiple keys and their associated HTML tag attributes in a React application

One of my links, specified with an a-tag, appears in this manner: <a href={ item.htmlReportUrl } target="_blank" rel="noopener noreferrer"> {item.htmlReportText}</a> The values for the href and the linktext are sourced from the following: ro ...

Sharing a boolean state between two pages using Material UI components

One challenge I've been facing is passing a boolean useState value between two pages. I found a helpful solution on this Stack Overflow thread: How to call useState from another Page? The main goal here is to display a success alert on a separate pag ...

Every time I try to call the event in jQuery for the second time, it fails to work

I am currently working on a website that features an image gallery powered by the jquery wookmark plugin with filtering capabilities. Recently, I integrated the colorbox plugin (which was provided as an example by wookmark) to enhance the user experience. ...

String variable representing the name of a React element

As I was reviewing the source code of a React UI library, I stumbled upon an interesting code pattern that I will simplify here: function Test() { let Button = "button"; // ... return <Button>Click me</Button>; } I'm curious about ...

What are the best ways to conceptualize the benefits of WebRTC?

I encountered a peculiar issue with the abstraction of the WebRTC offer generation process. It appears that the incoming ice candidates fail to reach the null candidate. While I have been able to generate offers successfully using similar code in the past, ...

The TypeScript error states that the argument type 'string | undefined' cannot be assigned to the parameter type 'string'

Receiving TS error that says "Object is undefined" I am attempting to retrieve the "userid" from my headers. However, I keep encountering the error message "Argument of type 'string | undefined' is not assignable to parameter of type 'str ...

The alert function in the Ajax web method is malfunctioning

Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert sa ...

Setting up a function in React to utilize an image stored in state

I have a function in my react component for image classification that retrieves the image from the img tag using document.getElementById: const img = document.getElementById('animal_image');. The image uploaded via the file input updates the sta ...

Guidelines for invoking a JavaScript function within an AngularJS controller

I have included a code snippet below. sample.js (function() { /*global angular */ 'use strict'; angular.module('myapp', ['spinner']) .controller('myCtrl', ['$scope', '$window ...

Retrieving JSON information from the server

I have been working with the knockout.js framework and adapted a basic contacts form example to suit my needs. I am able to successfully store values in my database, but I am encountering difficulties when trying to load values from the server. Despite h ...

Issue encountered with create-next-app during server launch

Encountering an error when attempting to boot immediately after using create-next-app. Opted for typescript with eslint, but still facing issues. Attempted without typescript, updated create-next-app, and reinstalled dependencies - unfortunately, the prob ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...