Wednesday, 15 October 2014

How to pass data from one controller or a html to another controller by route

How to pass data from one controller or a html to another controller:



-------
In the routes.js:

}, {
id : 'modetails',
url : '/moDetails',
templateUrl : 'views/moDetails.html',
controller : 'MoDetailsCtrl'
}, {
id : 'modetails',
url : '/moDetails/:peter',
templateUrl : '/views/moDetails.html',
controller : 'MoDetailsCtrl',
foodata: 'iii'
resolve : {
peterxxx : function(peterService) {
return peterService.getpeterMessage();
}
}

}];


------
in the controler
  angular.module('fitForTheFutureApp.controllers.MoDetailsCtrl', [])
    .controller('MoDetailsCtrl', function ($scope, $http, $routeParams,$route,peterxxx) {
   
    $scope.xx = $routeParams.peter;
    $scope.fff = $route.current.foodata;
    $scope.peterxxx = peterxxx;
    console.log("$scope.xx == " + $scope.xx);
    console.log("$scope.fff == " + $scope.fff);
    console.log("$scope.peterxxx  == " + $scope.peterxxx);



I will use pictures to show above methods except the service one:

method1:








method2






































   

No comments:

Post a comment