Utilizing Angular's factory and $resource in your project

For my first app using Angular, I have defined my service as:

angular.module('mean.testruns').factory('Testruns', ['$resource', function($resource) {
    return $resource('testruns/:testrunId', {
        testrunId: '@_id'
    }, {
        update: {
            method: 'PUT'
        }
    });
}]);

I have also added another URL on the rest server:

'/testcases/:testcaseId/testruns'

How can I incorporate this into the existing Testruns factory function?

My current controller looks like this:

$scope.findOfTestcase = function() {
    //Need to correct this
    Testruns.query({testcaseId:$stateParams.testcaseId}, function(testruns) {
        $scope.testruns = testruns;
    });
};

$scope.findOne = function() {
    Testruns.get({
        testrunId: $stateParams.testrunId
    }, function(testrun) {
        $scope.testrun = testrun;
    });
};

Answer №1

Not entirely certain, but here's a possible solution:

angular.module('mean.test').factory('Testruns', ['$resource', function($resource) {

    return {
        runs: $resource('testruns/:testrunId', ...),
        cases: $resource('testcases/:testcaseId', ...)
    }
}]);

Implementation example:

app.controller('ctrl', ['$scope', 'Testruns', 
    function($scope, Testruns) {
        $scope.testCases = Testruns.cases.query();
    }
])

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

Are you interested in creating dynamic tables/models with Sequelize?

Currently, I am exploring a theoretical question before diving into the implementation phase. The scenario is as follows: In my application, users have the ability to upload structured data such as Excel, CSV files, and more. Based on specific requirement ...

Using React components to create an anchor element for a popover display

Hey, I'm just starting out with React and trying to wrap my head around Hooks like useState. It's a bit challenging for me, and I want to keep things simple without making them too complex. I've encountered an issue when transitioning a Rea ...

obtain the final result once the for loop has finished executing in Node.js and JavaScript

There is a function that returns an array of strings. async GetAllPermissonsByRoles(id) { let model: string[] = []; try { id.forEach(async (role) => { let permission = await RolePermissionModel.find({ roleId: role._id }) ...

What is the purpose of the assertEquals() method in JSUnit?

Currently, I am exploring unit test exercises with a HTML5/JS game that I created and JSUnit test runner. The simplicity of the setup impresses me, but I have noticed that even the documentation lacks a clear explanation of what assertEquals() truly does. ...

What is the best way to input keys into the currently selected element?

During my experimentation, I discovered that several modals and dropdowns in my tests open with their input boxes automatically focused. I found a way to verify if an element is in focus, but I'm wondering if there's a quicker method to input ke ...

What is the most effective way to access a variable from a service in all HTML files of Angular 2/4 components?

In my angular 4 project, I have an alert service where all components can set alerts, but only specific components display them in unique locations. My question is: how can I access a variable from this service across all HTML files? The structure of my s ...

Discovering distinct colors for this loading dots script

Looking for assistance with a 10 loading dots animation script. I'm trying to customize the color of each dot individually, but when I create separate divs for each dot and control their colors in CSS, it causes issues with the animation. If anyone ...

Direct attention to the modal display

I'm having trouble auto-focusing an input field when a modal is displayed. Here's what I've tried, but it doesn't seem to be working: jQuery(document).ready(function($) { $('#myModal').on('show.bs.modal', functi ...

PHP query will execute even in the absence of clicking the button

I'm encountering an unusual issue. I've defined a query to insert two names into the database, and I've used Javascript(Jquery) to ensure it only runs when the create button is clicked. However, the script seems to be executing every time I ...

Updating default values in reactive() functions in Vue 3: A step-by-step guide

Currently, I am in the process of developing an application using Nuxt 3 and implementing the Composition API for handling async data. The specific scenario I am facing is this: I have a page that displays articles fetched from the database using useLazyFe ...

React-navigation installation in React Native project failed due to ENOENT error - file or directory does not exist

Encountering errors during the installation of react-navigation in my react native project using npm install @react-navigation/native https://i.sstatic.net/uKiPQ.png The installation process reaches halfway, pauses for a few minutes, and then displays an ...

The click event will not be triggered if the element is removed by my blur event

My dropdown list is dynamic, with clickable items that trigger actions when clicked. Upon focus, the list displays suggested items When blurred, the list clears its contents The issue arises when blur/focusout events are triggered, causing my element to ...

Verify if the program is operating on a server or locally

My current project involves a website with a game client and a server that communicate via sockets. The issue I'm facing is how to set the socket url depending on whether the code is running on the server or my local PC. During testing and debugging, ...

Strategies for redirecting a PDF download response from an API (using node/express) to a user interface (built with React)

I have a specific setup where the backend server generates a PDF, and when a certain endpoint is visited, it triggers the download of the PDF. However, due to security restrictions, I cannot access this endpoint directly from the frontend. To overcome this ...

The custom caching strategy was not implemented for the API response in web-api-2/OWIN

Starting with web-api 2 has presented me with a question: how do I set caching settings? I've created a custom caching-message-handler as shown below (simplified for this post) public class CachingMessageHandler : DelegatingHandler { private void ...

Encountered an issue while trying to send an email through the Gmail API: Unfortunately, this API does not provide

I am attempting to use the Gmail API to send emails. I collect user data and convert it to a base64url string. After obtaining the raw value, I attempt to send the email using a POST request. var ss=new Buffer(message).toString('base64') var ...

unable to use ref to scroll to bottom

Can someone explain to me why the scroll to bottom feature using ref is not functioning properly in my code below? class myComponent extends Component { componentDidMount() { console.log('test') // it did triggered this.cont ...

troubles with compatibility between bootstrap.css and IE11

I am currently developing a web application using AngularJS and bootstrap.css. While everything appears fine on Chrome, I am facing some formatting issues on both Firefox and IE11. HEAD <head> <meta charset="utf-8"> <meta http-equi ...

E/launcher - The operation ended with a 199 error code

Hey there, I am new to Angular and Protractor. I keep receiving the error message "E/launcher - Process exited with error code 199" in my code. // conf.js exports.config = { //seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['spec.j ...

Hold on until the element becomes clickable

When attempting to logout from the menu drop down, I encountered an error stating "Unable to locate element." I suspect there may be a synchronization issue as adding a `browser.sleep(5000);` allowed the tests to pass, but this solution is not stable. ...