Click here to Skip to main content
15,888,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I used mongodb and nodejs and create REST API(for example "http://localhost:3000/Records") but now i want to connect this API to angularjs application.

What I have tried:

CREATED rest API METHODS LIKE HTTP://LOCALHOST:3000/DETAILS.
Posted
Updated 26-Aug-16 3:30am

1 solution

To access a rest API from angular, inside your controller for whatever portion of your app is accessing it, you'll need to use $http.get to access it.

JavaScript
app.controller("YourNameForController", ['$scope', '$location','$routeParams', '$http', function ($scope, $location, $routeParams, $http) {
    $scope.mymodel = {};
    
    $http.get("HTTP://LOCALHOST:3000/DETAILS").then(function (value) {
        var data = value.data;
        $scope.mymodel = data;
    });
}]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900