how to pass json response from one html page to another html page using angularJs?

Anita Mehta

I have api for search functionality which has written in Laravel PHP.When I type some string in input tag and click on search button, then I am geeting the json response.

Now what I have to do is on ngClick a new html page should open say "search.html" with display the json response using angularjs.

I am not able to do, may be my lake of knowledge:). Can anybody tell me how can I do this.

Here is my code:

// Search Controller

QAApp.controller('SearchCtrl', function ($scope, $http) {

  $scope.search = function (searchtag) {
           var request = $http({
                          method: 'GET', 
                          url: server + 'api/question/tagged/' + searchtag,
                        });
                request.success(function(data, status, headers, config) {
                console.log(data);
                $scope.qa = data;
            });

        }

  });

html page is :

<div class="collapse navbar-collapse navbar-ex1-collapse" ng-controller = "SearchCtrl">
                        <div style = "float: right; margin-top: 7px;" class="col-sm-3 col-md-3">
                            <form class="navbar-form" role="search">
                                <div class="input-group">
                                    <input type="text" class="form-control" placeholder="Search...." name = "tag"  ng-model = "tag">
                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-primary"  ng-click = "search(tag);">
                                            <span class="glyphicon glyphicon-search"></span>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
V31

Over here you have two different pages and whenever you are moving from one page to other (no SPA) the page will complete refresh....so if one is thinking of having it in global variables, services or even $rootScope that will not work as these variables will get refreshed.

In order to cope up then we either need to work with cookies, querystring or the browser localStorage.

In order to use local Storage in Angularjs you need to include a script in both the pages for angular-local-storage Github Link

Code Example how to use it:

angular.module('yourModule', ['LocalStorageModule'])
.controller('yourCtrl', [
  '$scope',
  'localStorageService',
  function($scope, localStorageService) {
    // Start fresh
    localStorageService.clearAll();

    // Set a key
    localStorageService.set('Favorite Sport','Ultimate Frisbee');

    // Delete a key
    localStorageService.delete('Favorite Sport');
}]);

/*
To set the prefix of your localStorage name, you can use the setPrefix method 
available on the localStorageServiceProvider
*/
angular.module('yourModule', ['LocalStorageModule'])
.config(['localStorageServiceProvider', function(localStorageServiceProvider){
  localStorageServiceProvider.setPrefix('newPrefix');
}]);

Library main functions:

  1. .set : to set a key value in the localStorage space
  2. .clearAll: clear all the keys in localStorage
  3. .delete: delete a key
  4. .get: get a key from localStorage

Working Fiddle

Reference of what local Storage is actually about

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pass data from one html page to another using javascript?

From Dev

how to pass value one page to another page using html

From Dev

How to pass data from one page to another page html

From Dev

how to pass the value from one page to another page in html

From Dev

How to pass values from one Html to another Html page?

From Dev

How to pass the data from one html to another html page using JavaScript in Phonegap?

From Dev

How to pass the data from one html to another html page using JavaScript in Phonegap?

From Dev

How to redirect from one html page to another html using Springboot

From Dev

How to insert one html page into another html page using custom directive in AngularJS?

From Dev

How to pass data from a html page to another?

From Dev

how to transfer data from one html page to another using javascript

From Dev

How to pass Array of JSON Data from one html page to other html page?

From Dev

How to pass Array of JSON Data from one html page to other html page?

From Dev

How to use data from one HTML page to retrieve data to be used on another HTML page using ajax

From Dev

Pass Search value from one html page text box to another html page text box on click using cookies?

From Dev

How to jump one page to another page using HTML and JQUERY

From Dev

Angularjs pass value from one page to another

From Dev

Pass form data from one html page to another html page and datase in flask

From Dev

How to pass JSON response from struts 2 action class to HTML page

From Dev

how to redirect one html page to another using button click event in angularjs

From Dev

How To Pass Form Data from One Page To Another using FlaskApp

From Dev

using one html page's dropdown list to another html page

From Dev

how to send a parameter from an html page to another with angularjs

From Dev

How to pass a value from a parent window to another html page using javascript?

From Dev

How to pass a value from a parent window to another html page using javascript?

From Dev

How to call a function in one html page in another html page

From Dev

How to get data from one php page using ajax and pass it to another php page using ajax

From Dev

How do I open the content from an html page into a dialog from another html page with href using jQuery?

From Dev

Using a Google Web App - Can I pass a variable from one HTML page to another within the same web app

Related Related

  1. 1

    How to pass data from one html page to another using javascript?

  2. 2

    how to pass value one page to another page using html

  3. 3

    How to pass data from one page to another page html

  4. 4

    how to pass the value from one page to another page in html

  5. 5

    How to pass values from one Html to another Html page?

  6. 6

    How to pass the data from one html to another html page using JavaScript in Phonegap?

  7. 7

    How to pass the data from one html to another html page using JavaScript in Phonegap?

  8. 8

    How to redirect from one html page to another html using Springboot

  9. 9

    How to insert one html page into another html page using custom directive in AngularJS?

  10. 10

    How to pass data from a html page to another?

  11. 11

    how to transfer data from one html page to another using javascript

  12. 12

    How to pass Array of JSON Data from one html page to other html page?

  13. 13

    How to pass Array of JSON Data from one html page to other html page?

  14. 14

    How to use data from one HTML page to retrieve data to be used on another HTML page using ajax

  15. 15

    Pass Search value from one html page text box to another html page text box on click using cookies?

  16. 16

    How to jump one page to another page using HTML and JQUERY

  17. 17

    Angularjs pass value from one page to another

  18. 18

    Pass form data from one html page to another html page and datase in flask

  19. 19

    How to pass JSON response from struts 2 action class to HTML page

  20. 20

    how to redirect one html page to another using button click event in angularjs

  21. 21

    How To Pass Form Data from One Page To Another using FlaskApp

  22. 22

    using one html page's dropdown list to another html page

  23. 23

    how to send a parameter from an html page to another with angularjs

  24. 24

    How to pass a value from a parent window to another html page using javascript?

  25. 25

    How to pass a value from a parent window to another html page using javascript?

  26. 26

    How to call a function in one html page in another html page

  27. 27

    How to get data from one php page using ajax and pass it to another php page using ajax

  28. 28

    How do I open the content from an html page into a dialog from another html page with href using jQuery?

  29. 29

    Using a Google Web App - Can I pass a variable from one HTML page to another within the same web app

HotTag

Archive