Combining the results of two functions in the AngularJS view

I am facing an issue with two functions on my $scope: getTotal1() and getTotal2().

Interestingly, when I use them individually like this:

<div>{{getTotal1() || 0}}</div> <!-- it works -->
<div>{{getTotal2() || 0}}</div> <!-- it also works -->
<div>Grant total: {{getTotal1() + getTotal2() || 0}} <!-- this is not working -->

I can't seem to figure out why the sum of these two functions isn't displaying. Any ideas what could be causing this issue?

Edit I should note that both of these functions return a positive integer value of 0 or greater.

Answer №1

Check out this plunker I created for you:

http://example.com/plnkr123

Do you see any issues in the code?

Looks like it's functioning correctly!

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

Guide to modifying the value of a JSON attribute in JavaScript

Here's a snippet from my json file: { "@id": "2", "@samsid": "d7058536c89b46c0b58117eff64372f7", "@productname": "Another paid for", "@downloaddate": "2013-05-28 11:37:12Z", "@downloadlocation": "2AFoGZVJpFHzspQD9UoE2C4VFYc8idiO4ebaRx4uEvtG+ ...

Unable to resize div element using the change size function

When I click on a div, it should change size, and I want to write the onclick command in an external .js file instead of directly in the html page. Currently in html: <div id="box1" class="kaesten" onclick="changeSize('box1')"> Title 1 &l ...

I am encountering some difficulties with the functionality of the angularjs dialog

I've been attempting to integrate an AngularJS dialog feature into my application by following the examples provided on material.angularjs.org. However, despite copying everything accurately, I am unable to get it to function. Can anyone help identify ...

Using a semicolon right after "id" is recognized as an unexpected token

I encountered an issue while attempting to run my express.js program. The main server fails to start and displays the following error message. id; ^ SyntaxError: Unexpected token ; at new Script (vm.js:80:7) at createScript (vm.js:274:10) ...

ui-router: Converting URL parameters

Is there a way to seamlessly transform URL parameters? Let me illustrate with a scenario. Our URL structure is like this: /shopping/nuts/:productId /shopping/berries/:productId /shopping/juice/:productId The products in our app, fetched from an API, may ...

Discord.js reaction event handling

I'm in the process of developing a starboard feature for my bot, and everything is functioning well. However, I am facing an issue where I want the bot to ignore reactions made by the author of the original message. Here is the current code snippet: ...

There is an excessive number of import statements on the homepage during the initialization of the framework

For my angular project, I initially planned to organize each page and service in separate .js files. However, as I started coding, I realized that my index.html file was becoming overloaded with import statements. This could potentially slow down user load ...

Removing files from the S3 bucket and database simultaneously. Execute each function sequentially

Struggling with an API call that should delete an image from both an S3 bucket and a MySQL database. However, encountering an issue where the S3 image cannot be found because it is being deleted from the database first. // Router code: //req.body is an ar ...

Encountering a repetitive setState issue within an array in Next.js

I'm struggling to find a solution for my issue - everything loops correctly the first time, but after looping twice in the array I encounter an error "TypeError: props.imgData[index] is undefined". Below is the code snippet : import React, { useEffec ...

React throws an error when attempting to switch to a login element with an invalid return type

I'm encountering difficulties connecting my login and signup pages to the home page in React. Here is the project's basic structure: --src --assets --components --elements --layout --login_components Login.js --signup_c ...

What might be causing the button switch case JavaScript functionality to not work properly?

In my Worklight project, I have a code snippet that is supposed to capture the value of a button that a user clicks on and then display that value in a label. However, when I run the project, none of the other functions I have defined seem to work. Strange ...

Steps to extract the input value using Selenium IDE

What is the proper way to retrieve the value of the field "value" from an input using Selenium IDE? This value can vary, so I need to be able to recover it for reuse. Here is my input field: <input class="myClass" type="text" value="15" name="myNam ...

What steps should I take to create my own category organizer?

Currently, I am in the process of creating a category organizer for my website. Radio buttons can quickly become overwhelming, while select/option buttons are not very noticeable. After some searching, I came across this unique category organizer and I am ...

Unable to provide desired array return

Greetings from a newcomer to StackExchange! I recently delved into the world of programming and am currently learning JavaScript. My goal is to create an array of random numbers with 'n' size in order to experiment with sorting and searching algo ...

Create a chronological timeline based on data from a JSON object

Here is a JSON object generated by the backend: { "step1": { "approved": true, "approvalTime": "10-11-2021", "title": "title 1", "description": "description 1" ...

What is the best way to eliminate a script tag based on both its content and source url?

Is there a way to remove a script tag (<script>...</script>) based on its content or src property? For example: <script type="text/javascript"> var adfly_id = 2776246; </script> <script src="https://cdn.adf.ly/js/display.js ...

"Unexpected behavior: Angular route parameters are found to be empty upon receiving the API

Seeking to extract parameters from the urlcallback received from an external authentication source, within my Angular project using angular-route/$routeProvider The API redirect is as follows: http://localhost:8080/dist/?somevar=someval&val2=someot ...

Need help setting parsed values on jQuery Autocomplete after Keyup event?

I am using the Bing API to retrieve values by accessing this link: When I parse and append the results on keyup, it works fine. However, when I try to set the results on jQuery's autocomplete, it does not display properly. For example, you can view ...

Node JS encountered an unhandled promise rejection warning, while React received a preflight response

Working with React JS: Take a look at the code snippet below: ....some code...... verifyTokenResults = await axios.post('http://localhost:5000/otp/token/verify', {accessToken: authToken}) Here, I am sending a token from a React component to a ...

Combining arrays to create a single object: A step-by-step guide

Here is the current output I have, which contains multiple arrays: ["{"486|575":2,"484|568":4}", "{"486|575":2,"484|568":4}", "{"481|570":1,"482|564":1}"] My goal is to combine these arrays into an object with the following output using JavaScript/jQuery ...