$q, postponement, and fractional deployment

I can't figure out why this code isn't functioning as anticipated:

func = ->
   deferObj = $q.defer()
   $timeout ->
      deferObj.resolve({foo:'bar'})
    ,1000
    return deferObj.promise


showData = (data)-> 
   console.log(data.foo)

func().then(showData)                  # not working as expected

func().then((data)-> showData(data))   # works perfectly when used like this - prints "bar"

Why is the then method not properly curried as expected?

Answer №1

.then(cb) is the correct syntax, not .then(data).

To retrieve data, you must pass a callback function that accepts data as an argument:

.then(function(data){ //you can manipulate data here });

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

Configuring API paths based on environment variables with Express and Angular deployed on Heroku

I have a specific task I need help with, and I'll provide more details below. In my main Angular JavaScript file, I need to define a string that determines the server path for my app depending on whether it's in a production or staging environme ...

An unanticipated syntax issue has been encountered in the React build chunk files and manifest JSON

I am seeking to host my react application from {baseurl}/admin/. After conducting some research, I came across this solution- Here is my Express code- app.use('/admin/', express.static(path.join(__dirname, '/admin/frontend/'))); app.g ...

Locate and substitute `?php` and `?` in a given string

I am facing a challenge with inserting a large string of valid HTML code into the DOM, as the string also includes PHP code. When Chrome renders the code, it automatically comments out the PHP sections. The PHP code is encapsulated in <?php ... ?>, s ...

I am looking to implement a post request feature in JavaScript and HTML that is similar to the functionality in my Python code

Although I am proficient in Python, I am struggling with JavaScript while trying to create an HTML page. I have a Python code snippet that I would like to replicate in JS. Can anyone provide some assistance? :) Here is my Python Code: import requests pos ...

The struggle of accessing child components using ViewChild in Angular

I am facing an issue with a dialog box that is supposed to display a child component separately. Below is the code for the child component: @Component({ selector: 'userEdit', templateUrl: './edituser.component.html', styleUrls: [ ...

Which is more advantageous in this scenario: using .fail() or .timeout()?

When it comes to handling timeouts on my $.ajax() calls for a jQueryMobile project, I have discovered two potential methods. The .fail() function appears to be the more generic option: if the call fails for any reason, an error stack is returned and then ...

Managing consecutive synchronous side effects that are dependent on each other using React hooks

I am currently in the process of transitioning my application from using Redux to the new context and hooks, but I am facing challenges when it comes to handling a series of synchronous side-effects that rely on the response of the previous one. In my exi ...

Tips for implementing the new useState value in your code

Using DataGrid Material UI, I am facing an issue where the selected row is not being deleted when clicking on the delete button. The problem arises from setting the ID value in the useState hook and encountering asynchronous behavior in deleting the rows. ...

Using Angularjs for seamless image uploading

Encountering an issue after adding 'ngFileUpload' to my module. Here is my code: var app = angular.module('myApp', ['ngFileUpload']); Along with the following route configuration: angular.module('myApp') .config ...

What is the best approach to converting a set of vertex indices greater than four into a usable format?

I am developing a method to transform the data from 3D files into THREE geometries. The data is formatted as follows: {"N":"name of the block","V":[[0,1,2]..[N1,N2,N3]],"F":[[0,1,2]..[M1,M2,M3]],"P":[[O1,O2,P3,..,Op]..[..]]} The meaning of N is self-expl ...

When extracting text using .text(), remember to include spaces between td elements

Is there a method to include space between td's when using .text()? I have searched extensively on Google but could only find information on how to trim space. The code I am currently using is as follows: for (var i = 0, len = rows.length; i < l ...

Using an AJAX/HTML/JavaScript approach to enable/disable a button for generating reports and then re-enabling it

A Spring-MVC controller is used to generate a PDF report when a get request is made. The controller includes headers such as "application/OCTET-STREAM", "Content-Disposition", and "attachment; filename=\"" + filename + "\"" in order to prompt the ...

Swap out values in a string if they match any of the variables in an array

Let's work with an array of objects: const data = [ { key: '%KEY1%', value: 'value1' }, { key: '%KEY2%', value: '%KEY1% abc' }, { key: '%KEY3%', value: 'xyz' } ]; Now, we have a string ...

Steps for dynamically adding a ng-click handler:1. Create the function

I attempted to implement ng-click on a dynamically generated button, but encountered issues with its functionality. Despite trying various solutions from this forum, none of them have proven successful. Here is my HTML code: <body class="max_height" n ...

Tips for stopping the Print dialog box in Mozilla when using the CTRL + P shortcut

When I press CTRL + P on my view, a JavaScript code is triggered. The code works perfectly on all browsers except Mozilla; I cannot seem to block the Print Dialogue on that browser. Is there something wrong with my code? I have been attempting to implemen ...

Vue.js build fails with JSON errors rendering a blank page

As I was building my first project to learn more about vue.js, I encountered an issue when using npm run build. It resulted in blank pages with errors related to JSON. However, when I used the typical npm run serve command, the page looked great and worked ...

Unable to link to 'mdMenuTriggerFor' as it is not a recognized attribute of 'button'

During the execution of my angular application using ng serve, I encounter the following error: Can't bind to 'mdMenuTriggerFor' since it isn't a known property of 'button' Despite importing all the necessary components, I a ...

How to resolve a TypeError saying "Object(...) is not a function"?

I've been attempting to display material-ui tabs as a component on another page, but I'm encountering an error that causes the code to break when loading the page with this component. I've tried two different methods of rendering this compo ...

Using AJAX to Verify Google Recaptcha V3 Response

One of my functions is used to make an Ajax POST request : function ajaxPost(url, data, callback) { var req = new XMLHttpRequest(); req.open("POST", url, true); req.addEventListener("load", function () { if (req.status >= 200 && ...

Utilizing yield (generators) in conjunction with selenium webdriver promises: A comprehensive guide

Trying to harness the power of generators in node 0.11.x to streamline my Selenium tests has proven to be a bit challenging. Despite using the official selenium-webdriver module (ver 2.37.0) and co (ver 2.1.0) for generator creation, I find myself struggli ...