RAHUL RAHUL - 4 months ago 7
AngularJS Question

Sending data from one controller to another

I think this is a very simple problem but i'm not able to figure it out.

I have 2 controllers in my angularjs file..

analyzer.controller('AnalyzerController',function($scope,$http)
{
$scope.builds = [];
$http.get('/List').success(
function(data) {
$scope.builds = data.responseData;
});

$scope.showbuild=function(item){
alert(item);
}

});




analyzer.controller('Information',function($scope,$http)
{
$scope.cases = [];
$http.get('/info').success(
function(data) {
$scope.cases = data.responseData;
});

});


I want to send the value of item in the first controller to the 2nd controller . Item is the value user selects from a box of html page.

Answer

Set state like this

$stateProvider

.state('page1', {
    url: '/page1/:id/:name'
});

in Your Controller inject $stateParams

then you can get data like

$scope.id=$stateParams.id;
$scope.name=$stateParams.name;
Comments