How to send data in $http function?


#1

We have created a rest api and gets the json array by $_GET .But we want to post the data to another page .How can we do it? We want to pass cat.id from index.html page through API to retreive all the data related to that cat.id only .How can we pass that id and post the data on the new page say index2.html?


#2
[quote="Jiten_08, post:1, topic:46704"]
om index.html
[/quote]

For the sake of simplicity, i will not use services but note that it is a good practice to code your business logic in the model/service layer

  1. in the controller for index.html, set the cat.id as global like so
    $rootScope.catId = cat.id;

  2. in controller for index2.html
    let us do a mock controller for index2.html

    .controller(‘index2Ctrl’,function($scope, $http){
    $scope.cats = {};
    var url = ‘yourRestApi/’+$scope.catId;
    $http.get(url).then(function(cats){
    $scope.cats = cats
    });
    })