Using Angular: applying a function to an HTML variable

I am trying to create an overlay feature for a button using the following code:

<div id="overlay" ng-if="vm.showOverlay">{{control}}</div>
<button ng-mouseover="vm.showOverlay = true" ng-mouseleave="vm.showOverlay = false" class="btn" ng-class="{classWhite: control.values.value1, classRed: control.values.value2, classOrange: control.values.value3}" ng-click="colorChange(control)"></button>

However, the data I receive from:

<td ng-repeat="control in general">

is a complex object that requires a specific function to extract the value to be displayed:

    $scope.stateFromControl=function(control){
        var values=control.values;
        var resultValue=(values.value1)?0:(values.value2)?1:2;
        return translateState(resultValue);

    }

Unfortunately, inserting this function directly into the {{}} does not work. How can I properly implement it?

Answer №1

For a temporary solution, I successfully implemented it by introducing a variable state that I update with every change:

var updatedValue={
            id: i,
                name: facility,
            state: translateState(oldStatus),
            values:{
                value1: oldStatus==0,
                        value2: oldStatus==1,
                        value3: oldStatus==2
            }
        }

This variable can be utilized as follows:

<div id="overlay" ng-if="vm.showOverlay">{{updatedControl.state}}</div>

Although not perfect, this method is currently functional.

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

Sharing scope variables between multiple dynamically created directives

Find my Plunkr example here: http://plnkr.co/edit/9LcYbn1468miu5McgPqR?p=preview I successfully added the form to the variable inside the options parameter, but I am looking to bind it to a different location outside of the options parameter. I have a cu ...

What are some strategies to troubleshoot unexpected outcomes when using useEffect in React?

import { createContext, useState, useEffect } from "react"; const UniqueContext = createContext(undefined); const UniqueContextProvider = (props) => { const [ items, setItems ] = useState([]); useEffect(() => { console.log(items ...

Ways to automatically change a URL into a clickable link upon pasting

When attempting to paste a URL into the text box such as https://stackoverflow.com/, it does not automatically convert to a hyperlink. I previously tried using regular expressions in this related question. The function I implemented worked correctly, howe ...

Most efficient method for transmitting and receiving a color array through websockets

I am looking to control a large number of LEDs, purely for entertainment purposes and not work related. The user interface (UI) is coded in javascript and will be sending data (a color array) approximately 60 times per second. The LED driver is a microco ...

Deciphering HTML within a Vue attribute: Tips and tricks

I'm having trouble converting some code to Vue. There seems to be a rendering difference in the alt attribute of an image, and I can't figure out how to interpret the html within the attributes. I've searched for solutions but haven't f ...

Adapting the visual display according to the selected radio button output

Hey there, I've been working on a project of mine, but I'm struggling to fix a problem that has been puzzling me for quite some time. My webpage calculates the amount of calories needed to achieve specific training goals. I want to display three ...

Steps for "submitting" a portion of a form with jQuery

I have a form that resembles a spreadsheet layout. My goal is to submit specific fields from a row to the server using jQuery Ajax whenever the user navigates away from that row. The challenge arises because the page consists of one large form, making it n ...

The issue related to a form control named 'No value accessor' lacking an accessor

As I work on a stackblitz for an issue with child-parent communication, a different problem has arisen. Specifically, I am encountering the error message: No value accessor for form control with name: 'endDateFC'. The same error is occurring for ...

Adjust background color on click using JavaScript

Could someone provide me with the JavaScript code to change the background color of a page from blue to green when a button is clicked? I have seen this feature on many websites but haven't been able to write the code myself. I am specifically lo ...

Angular encountering issue binding array in $http POST request

Currently, I am in the process of setting up a post function using Angular. The HTML form I have includes two text boxes for user input and a drop-down menu for selecting from a number of choices. While binding the text boxes is not an issue, I am facing d ...

Is it necessary to initialize the database before invoking the main controller in Ionic Sqlite using Ionic and ngCordova (AngularJS)?

My query involves the initialization of a database function called "initDB". this.db = $cordovaSQLite.openDB({ name: "pasa.db" }); $cordovaSQLite.execute(this.db,'CREATE TABLE IF NOT EXISTS dashboard (id integer primary key, orders_open integer,order ...

Is there a way to prevent users from dropping links or images into an input field

Is there a way to prevent users from dropping links or images into an input box? I'm open to using JavaScript or jQuery. Here is what I have attempted so far: http://jsfiddle.net/eRqzz/ $("input#fl_search, input#fl_search_bdy").on('drop', ...

Tips for staying on the same page when hovering over a table

My hover table contains multiple pages, with each row offering various actions one can take with an item. After performing an action, the page refreshes and returns to the first page of the table. Is there a way to stay on the same page after executing a ...

Generate an error upon submission if a particular checkbox is chosen from a group of checkboxes

To prevent form submission and display an error message if checkbox id="check1" is selected, follow the code below: <form name="form1" method="post" action=""> <span id="group"> <input type="checkbox" name="check1" id="check1" ...

Utilize jQuery to initiate an AJAX request based on the data retrieved from a previous AJAX call, then retrieve the resulting array

When the page loads, I initiate an ajax call and receive an array in response. For each element with the name groupId in this array, I must make another ajax call to fetch the group's name and notes. My objective is to create a final array by combini ...

Arranging HTML elements using JavaScript or jQuery

Something seems off. The sorting doesn't work as expected. Check out the JavaScript code below: function sortDescending(a, b) { var date1 = $(a).data('date'); var date2 = $(b).data('date'); return date1 > date2; } ...

Distribute the capabilities of the class

Is there a way to transfer the functionalities of a class into another object? Let's consider this example: class FooBar { private service: MyService; constructor(svc: MyService) { this.service = svc; } public foo(): string { ...

Bootstrap: .stacked-navigation

Currently working on an app utilizing Bootstrap v3.3.5. I have set up a navigation bar and now looking to implement two different views. The first view is intended for tablets and computers, featuring icons alongside the menu item names without any dropdo ...

Are you facing an issue with loading external templates in AngularJS?

I initially believed that loading an external template with Angularjs was as easy as the code snippet below, <div ng-include='template/index.php'></div> However, when I try this in the browser, nothing gets displayed. What could be ...

Guide to extracting data from dynamic html table rows with jQuery

function AddRow() { $('#myDynamicTable tr:last').after('<tr><td class="itemName"><input type="text" style="width: 300px;"/><td class="itemQty"><input type="text" style="width: 50px;"/></td></td> ...