1

I have two pages in my angularjs application, I get some data from database to show in a table, then i doubleclick on a row and go to another page to show more details. The problem consists on how to send data from the first page to the second one to show them knowing that i have all the data i need to show in my variable "branchs" that i showed some of them in the first page, here is a part of my code :

var app= angular.module('MyApp' , []);
app.controller('Ctrl', function($scope, $http){
     $http.get('http://localhost:8080/Test_WS/test/branchs/brnch')
     .then(function(response) {
         $scope.branchs = response.data;

     })

     .then(function(response) {
     $scope.details = function (b) {
        window.location = 'http://localhost:8080/TestProject/CreateBranch.html'; 
     };
     });
});
Uncle Iroh
  • 5,748
  • 6
  • 48
  • 61
sansa
  • 11
  • 4
  • You should use services for share data beetween 2 controller – Akashii May 02 '17 at 15:24
  • You can use [localStorage](https://developer.mozilla.org/tr/docs/Web/API/Window/localStorage) to store the data but it is not good way to get data in new page. You must declare new DB request for spesific data and use it in new page. Because user can click multiple edit at the same time and it is buggy for use of localStorage. Or you can send the data in link if your data is short enough. – Burak Akyıldız May 02 '17 at 15:33
  • should I do that even if i have two controllers in seperate modules?? – sansa May 02 '17 at 15:37

1 Answers1

0

Since you have the data in a variable i recommend to create an factory. In the first page create new factory method and save data in a varible using a factory method. Once you navigate to second page call another factory method which return the data

Another way you can do this using rootscope. But i would not recommend this because as the application get extend code will get confused and it will be overhead to the memory

Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80