"Erroneous path being displayed by .query() function

Currently, my function utilizes the query() method to display all tasks. The issue lies in it referring to users/tasks?status=completed.

What I actually require is

users/:user_id/tasks?status=completed
. How can I go about solving this?

var app = angular.module('Todolist', ['ngResource']);

  app.factory('Task', [
    '$resource', function($resource) {
      return $resource('/users/:user_id/tasks/', {id: '@id'}, {update: {method: 'PUT'}});
     }
   ]);

  app.controller('TasksCtrl', [
    '$scope', 'Task', function($scope, Task) {

      $scope.user = current_user

      $scope.tasks = Task.query(
        status: 'incompleted'
      );

    }
   }
  ]);

Answer №1

Kindly ensure that your controller is up to date.

 app.controller('TasksCtrl', [
    '$scope', 'Task', function($scope, Task) {
     $scope.user = null; //current_user please define this variable it will cause for undefined error
    $scope.tasks = Task.query({status: 'completed', user_id : 12}); //'12' is user id , you can pass dynamically

 }]);

Factory code is :

app..factory('Task', [
    '$resource', function($resource) {
      return $resource('/users/:user_id/tasks/',
      {user_id: '@user_id'},
      {update: {method: 'PUT'}});
   }
]);

Working plunker

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

How can one easily display overflowing text when hovering over it?

My issue involves a p element that could potentially have lengthy text (I've used overflow: hidden; white-space: nowrap; text-overflow: ellipsis;). I want the text to appear as a floating link next to the cursor when hovering over the paragraph. Is th ...

Node server quickly sends a response to an asynchronous client request

Apologies for my lack of writing skills when I first wake up, let me make some revisions. I am utilizing expressjs with passportjs (local strategy) to handle my server and connect-busboy for file uploads. I believe passport will not have a role in this pr ...

Error encountered: Unable to locate module 'win-spawn'

After installing Generator-ionic in the directory where I generated the app, I attempted to run grunt server but encountered an error message stating: "Error: Cannot find module 'win-spawn'". ...

Transform the API response array into a different format, ready to be passed as a prop to a

Looking to incorporate the Vue Flipbook component into my project, which requires an array of image URLs for the "pages" prop. I am fetching post responses from the WordPress REST API. My goal is to extract the "image" property from the response array and ...

What is the best way to assign a unique number to every div id that is generated?

I am currently using a django for loop to retrieve data from a query set. As the information is displayed, I would like to have each item wrapped in a div tag with a unique id that increments by 1 for every instance. Is there a way to achieve this directly ...

The Angular 6 watcher fails to compile the imported less files within the main.less file

Currently, I am developing in Angular version 6 and utilizing Less for styling purposes. In previous Angular versions, I utilized the angular_cli.json file to include the main Less file, which functioned properly. Now, in the latest Angular 6 version, I ...

Integrating fresh components into a JSON structure

I've been attempting to insert a new element into my JSON, but I'm struggling to do it correctly. I've tried numerous approaches and am unsure of what might be causing the issue. INITIAL JSON INPUT { "UnitID":"1148", "UNIT":"202B", "Sp ...

What is the most effective way to organize a collection according to the specific order specified in another array?

I have an array of objects, with each element containing another nested object like this: data = [ { name: "A", type: "AA", children: [ { id: 1, name: "Child-A", admin: ["Y"] }], other: "NA" }, { name: "B", type: "BB", ch ...

What is the most effective method for invoking a callback within a nested scope?

I am facing a situation where my page needs to load data through multiple HTTP requests, followed by some logic execution in several directives within the same page. I am currently using a boolean flag to indicate when the content has been loaded. Init ...

The specified element type is not valid: only a string (for built-in components) or a class/function is expected when attempting to display a component

`Unhandled Runtime Error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you mi ...

Highcharts boxplot is currently malfunctioning by presenting inaccurate values for the high and median

I am currently working on generating a box plot based on a basic set of data: var box_plot = Highcharts.chart(container, { chart: { type: 'boxplot' }, title: { text: chart_title }, ...

Showing a div element when the submit button is clicked

I am working on a form with a radio button and a submit button. When the submit button is clicked, I want to show a hidden div. Below is my current code: <form action="" method="GET" name="myform"> <input type="radio" name="ID" value="total" ...

Maintaining the position of the screen as you type in information that is located outside of the container

I am encountering an issue with the input/text-area element in absolute position extending halfway outside the container. The screen position seems to follow the caret as I type, but I'd prefer to keep writing and have part of the text hidden beyond t ...

Retrieve childNodes of the Select All input using jQuery from the container node with the class name "container"

I am trying to retrieve the text value of all the childNodes within the container of the corresponding input when the Select All checkbox is checked. Currently, my code captures the text inside each input label. However, it only logs the label (e.g. &apos ...

Node: effectively managing SQL scripts with dynamic variable replacement

My SQL statements have grown quite large, and I want to store them as separate files with syntax highlighting. The solution I found on StackOverflow is perfect for my needs. In my case, I write SQL queries in JavaScript using Template Literal syntax for v ...

What is the method to design a file upload feature without a specific form using JavaScript?

I am currently working on a form that handles file uploads using jQuery and AJAX. The goal is to upload the files individually as JSON containing base64 data. Rather than uploading all the images at once, I want each image to be treated as if it were in it ...

Vue: Simple ways to retrieve state data in MutationAction

I'm having trouble accessing the state inside @MutationAction Here is the setup I am using: Nuxt.js v2.13.3 "vuex-module-decorators": "^0.17.0" import { Module, VuexModule, MutationAction } from 'vuex-module-decorators' ...

"Encountering Issues with Angular's Modules and EntryComponents during Lazy Loading

Upon lazy loading an Angular module, I encountered an issue when trying to open my DatesModal that resulted in the following error: No component factory found for DatesModal. Have you included it in @NgModule.entryComponents? The declaration and entryCom ...

What sets apart a traditional website from one that is pinned to the home screen?

While developing an html5/js game using Cocos Creator, everything runs smoothly on Safari browser when tested on my iPhone 5s or iPhone 6s. However, I encounter a frustrating issue when I pin the game website to my home screen for quick access and fullscr ...

Ensuring User Data is Current in the UI with Firebase Auth Callbacks

Below is the standard method for setting the user state to currentuser that is returned from onAuthStateChanged. I am looking for a useEffect hook that will be triggered whenever there is an update to the user's information. Unfortunately, I am unable ...