Are there any outcomes from using Angular in conjunction with httpService for POST and DELETE requests?

I've created an Angular service to handle all the HTTP requests necessary for my controllers to communicate with my API.

export interface IDummyEntityApiService {
    getAllDummies() : ng.IPromise<Array<Entities.IDummy>>;
}

class DummyEntityApiService implements IDummyEntityApiService {

    private http: ng.IHttpService;

    constructor($http : ng.IHttpService) {
        this.http = $http;
    }

    getAllDummies() {
        var url = "acme.com/api/dummies";
        return this.http.get(url).then(result => {
            return result.data;
        }, error => {
            // log error
        });
    }
}

This service can be used as follows:

dummyEntityApiService.getAllDummies.then(result => {
    // fill results into list
}, error => { 
    fancyToast.create("Ooops, something went wrong: " + error);
});

Now, I'm wondering how to implement the POST and DELETE functionalities. I am aware that the $httpService has methods like .post(url, data) and .delete(url), which both return IHttpPromise<{}>. However, casting them up to a IPromise doesn't seem logical since there is no data that needs to be resolved in these cases?

Answer №1

One way to run code after an HTTP request is complete is by utilizing promises. In Angular, you can use ng.IHttpPromise<any> for this purpose.

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

Implementation of asynchronous code in event handlers is necessary

In my AngularJS controller, I have implemented an event mechanism to communicate with external elements. One particular event is triggered to retrieve the URL where the data should be sent. The event handler reacts to this event by making an AJAX call usi ...

The VueRouter is unresponsive and not functioning as expected

I have been delving into Vue. Through the npm install vue-router command, I added vue-router to my project. Subsequently, I incorporated VueRouter and defined my URL paths within the VueRouter instances located in the main.js file. I created an About compo ...

Error: Knockout sortable array failing to render nested elements accurately

As a newcomer to Knockout.js, I have recently delved into the world of JQuery and the knockout-sortable project. My current project involves utilizing a complex data structure to present forms. Specifically, I am attempting to create a nested sortable arra ...

How can I emphasize the React Material UI TextField "Cell" within a React Material UI Table?

Currently, I am working on a project using React Material UI along with TypeScript. In one part of the application, there is a Material UI Table that includes a column of Material TextFields in each row. The goal is to highlight the entire table cell when ...

Is there a shortcut for creating interfaces that have identical sub properties?

We are seeking to streamline the interface creation process by utilizing shorthand for properties labeled from Monday through Sunday, each with identical sub-properties. interface Day { start: number end: number } interface Schedule { Monday: Day ...

Is it possible to showcase images on a webpage in real-time while it's being generated with the help of Flask and Python?

Trying to create a webpage that downloads media from my telegram account and displays it in real-time as images are downloaded one by one. Currently, all images are displayed at once after being downloaded, which is not the desired behavior. Now experiment ...

Enhance the appearance of the dropdown select option group with stylish design

What is the best way to style a select option group using ng-options ? HTML: <select ng-model="filteredBy" ng-options="obj_data.value as obj_data.title group by obj_data.group for obj_data in data"></select> JS: $scope.filteredBy = ' ...

The md-select component in AngularJS is not retrieving data from the controller as expected

I am struggling with my code that is not displaying options for md-select. This specific HTML page is not the main page of my project, but rather part of my first AngularJS application. As a newcomer to AngularJS, I would greatly appreciate any assistance. ...

Issue arising with Iframe failing to load content on subsequent attempts

I have a situation where I am rendering a partial view through ajax into an iframe within the main view. It works perfectly fine when testing locally, but after publishing it only works the first time and on the second attempt, it clears the body of the if ...

Displaying JSON data using AngularJS ng-repeat allows for dynamic rendering

Struggling to find the best way to showcase this JSON file in my Angularjs repeat. My attempt was to display the title from the JSON results like this: <div ng-repeat="x in results"> {{x.data[0].title}} </div> But unfortunately, I'm ...

How to Insert Data into SQLITE using Node.js and Retrieve the Inserted Object or Last Inserted ID

I've been struggling to retrieve the object I just inserted, following the example provided in the documentation. However, every time I try, I end up with an "undefined" result. Am I missing something here? Is it no longer possible? The sqlite3 libra ...

Combining edit and view functionalities in jqGrid form

I've been exploring the jqGrid wiki but I'm having trouble finding answers to a couple of things. It seems like it might be too customized. 1) Can jqGrid be configured to display all fields of a row when editing via form edit, but only make a fe ...

Angular: A guide to dynamically applying colors to elements with user input and storing them in a database

I am currently implementing a method to apply CSS colors and styles obtained from an API endpoint to HTML elements. Although I have achieved this functionality, I believe there may be room for improvement in terms of best practices. This is the current i ...

"MongoDB Aggregating Data with Nested Lookup and Grouping

I have 3 collections named User, Dispensary, and City. My desired result structure is as follows: { _id: , email: , birthdate: , type: , dispensary: { _id: , schedule: , name: , address: , phone: , u ...

How can one transform a json object into a json string and leverage its functionalities?

I recently encountered an issue with a JSON object that contains a function: var thread = { title: "my title", delete: function() { alert("deleted"); } }; thread.delete(); // alerted "deleted" thread_json = JSON.encode(thread); // co ...

What is the best method for showcasing this console.log information in an Angular application?

I have developed a feature that displays users who are online. While it works perfectly in the console log, I am struggling to show p as the result if the user is online. Below is the code snippet: ngOnInit() { this.socket.emit('online', { r ...

The image fails to display when using THREE.js and Panolens.js

Trying to create a 360-degree environment with informational buttons using THREE.js and Panolens.JS However, I'm unable to resolve why the image is not appearing. Continuously encountering the error: Uncaught ReferenceError: process is not defined. ...

Analyze items in two arrays using JavaScript and add any items that are missing

I am working on a JSON function that involves comparing objects in two different arrays, array1 and array2. The goal is to identify any missing items and either append them to array2 or create a new array called newArray1. Here is an example: const arra ...

Utilizing jQuery.post to generate a dynamic dropdown menu

I recently designed a dropdown list that functions well on a standalone page. However, I encountered an issue when attempting to display it in a table on another page using jQuery.post(). The contents appear to overflow from the dropdown list. The jQuery ...

Ensuring Form Accuracy - Mandatory Selection from Group

Currently, in the project I am working on, there are three textboxes that need to be validated to ensure at least one of them has been filled out. I have been researching custom validation with Angular directives and found that it is possible to set the v ...