setting a custom data attribute for a model

Within my HTML code, I included:

<div class="sli1"
     data-values="10, 20, 30, 40,50, 60, 70"

I am trying to find a way to connect the data-values to a model that I can use again with Angular. I have looked into ng-bind but I am struggling to understand how I can achieve this.

Answer №1

Here is the code snippet:

<div ng-app="myApp" ng-controller="myCtrl">
    <div class="sli1" data-values="{{ dataValues.join(',') }}">This is the div section</div>
</div>
<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.dataValues = [10, 20, 30, 40, 50, 60, 70];
    });
</script>

I hope this solution serves your needs.

Answer №2

Using the ng-list directive is a simple way to achieve this functionality, requiring only the use of an array instead of a string.

Example Markup

<body class="container" ng-controller="mainCtrl" ng-init="test=[10,20,30,40,50,60,70]">
  <input ng-model="test" ng-list="," />
</body>

Check out this Plunker demo for further reference.

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

Is it possible to utilize a single Promise multiple times?

// App.js sites[site_name].search(value).then(function(results) { console.log(results); }); // SearchClass.js Search.prototype.search = function(search) { var self = this; this.params['wa'] = search; return new Promise(function ...

Unable to retrieve the value of the concealed tag

Here's the code I'm working with: <html> <head> <script type="text/javascript"> var x = document.getElementById("2").value; document.getElementById("1").innerHtml = x; </script> </head> <bo ...

Obtaining the text content of a <div> element when clicked using Selenium

I am trying to extract the email address from the code snippet below, but I am unsure of how to do it. Any assistance would be greatly appreciated! <div class="taLnk hvrIE6 fl" onclick="ta.trackEventOnPage('Listing', 'Email', 774169 ...

Unexpected token { in Fuse-Box when using Typescript

Here's the beginning of my fuse.ts file import { CSSPluginOptions } from 'fuse-box/plugins/stylesheet/CSSplugin'; import { argv } from 'yargs'; import * as path from 'path'; import { CSSPlugin, CSSResourcePlugin, Env ...

What is the best way to remove an item from an object?

I have a checkbox that adds its id value to an array when checked, and I want to remove this value when it is unchecked. I attempted to remove the id using indexOf() + splice(), but I am unable to use indexOf() because I am dealing with an object. Does a ...

Python_scraping <li style="display: hidden;">

I am having trouble extracting the text from the following HTML using Selenium in Python. <div class="tt"> <ul style="list-style-type:none" id="abs2"> <li> Funeral rites have undergone significant changes due to the ...

JavaScript Flash player for iPad

As many of us know, the iPad does not support Flash. However, I am curious if the iPad sends any specific error messages that can be captured using Javascript. I realize one method is to detect the iPad from the user agent string, but I am interested in w ...

Error in Vue component when setting the background image URL

Here is my code snippet that sets the background image for a component: style() { return { "background-image": `url(${require(`../../../assets/images/${this .last_result}.png`)})` }; }, The expected URL should be ../../../assets/images/ ...

Automatically sync textbox width with gridview dimensions

My goal is to dynamically resize a number of textboxes so that they match the width of my gridview's table headers. The gridview will always have the same number of columns, but their widths may vary. However, as shown in the image below, the width va ...

What is the best way to clear all input data that has been displayed in every input field within a React js application?

import React, { useState } from "react"; import axios, { Axios } from "axios"; import { ContainerDiv, InnerDiv, StyledButton, StyledInput, } from "./StyledComponents"; function WeatherCard() { const [input, SetInput ...

What is the reasoning behind choosing multiplication over addition?

Checking if two arrays contain the same digits is crucial. Here's an example to illustrate this: [1,1,2] and [1,2,2] = false; [2,3,1] and [1,2,3] = true; [1,2,4] and [1,3,2] = false; [1,1,4] and [1,2,3] = false; This function seems to handle the com ...

Using the Table-multiple-sort feature in boostrap-table is not functioning properly when there are multiple tables present on a single page

I have implemented bootstrap-table along with the extension table-multiple-sort. The issue I am facing is when I include two tables on a single page (with the second table within a modal window), the multisort feature does not seem to work on the second ta ...

What sets apart initializing an Express app using "app = new Express()" compared to "app = express()"?

Throughout my experience, express apps have always been initialized like this: var express = require('express') var app = express() However, today I came across an example where a new operator was used: var Express = require('express&apos ...

Is there an undefined error when clicking on a row in a dynamically created table?

When creating a table and adding a row click event with the purpose of retrieving the value of the first td, the following code is used: function bclick(){ var result=[]; SAPget.step4QueryTable(function(data){ var tbody=document.querySelector( ...

I'm experiencing an issue with res.redirect() as it is not directing me to the expected page. Despite no errors being shown, I am left wondering what

Despite everything working as expected, I am facing an issue with redirecting the user to a different URL after they send a message. I have tried using res.redirect from the server side in response to an AJAX POST request, but it seems like I am still on t ...

How to dynamically update data in Angular without the need for a page refresh or loading?

Looking to enhance a wishlist feature by enabling users to delete items from the list without the need for a page refresh. Here's my approach: wish.controller('wishCtrl',['$scope','$http','$cookies','$wind ...

"Encountering a 404 error while attempting to forward to an HTML

I've been encountering an issue while trying to transition from a JSX page to an HTML page. Every time I attempt to do so, I receive a 404 error stating that the page doesn't exist. It's puzzling because it is clearly present in my files and ...

Unable to get PrependTo to remove itself when clicked

Below is a custom jQuery script I put together: $(function(){ $("a img").click(function() { $("<div id=\"overlay\"></div>").hide().prependTo("body").fadeIn(100); $("body").css({ ...

unable to make a request to the express server with axios

I am in the process of developing a chat application similar to whatsapp. One of the key features I'm working on is that when a user clicks on another person's name, their chats will be displayed. However, currently, I'm facing an issue wher ...

Tips for loading data without disrupting the current scroll position

When data is prepended in a given set, why does the scroll position change? I notice that when I scroll to the top and prepend new data, the scroll position goes back up. However, on platforms like Facebook and WhatsApp, the scroll position remains the sam ...