Q:

Pass value from one controller to another in angular js1

I am using $rootScope for passing value from one controller to another but i did not get the value in second controller(cart).  
    x.controller("first",function($scope,$http,$rootScope){
    $scope.cart1=function(x,y){
        $rootScope.img=x;
        $rootScope.login=y;
    }
    });
     x.controller("cart",function($scope,$rootScope){
    $scope.cart2=$rootScope.img;

    console.log($scope.cart2)
    });

A:

$rootScope does not get the value assigned if you simply define in controller, you need to transfer the data from controller1 to controller2 based on some event
DEMO

var x =angular.module('app', [])
 x.controller("first",function($scope,$rootScope){
    $scope.cart1=function(x,y){
        console.log(x);
        $rootScope.img=x;
        $rootScope.login=y;
    }
 });
 x.controller("cart",function($scope,$rootScope){
     
     $scope.getData=function(){
     $scope.cart2=$rootScope.img;
    console.log($scope.cart2)
    };
 });
<!DOCTYPE html>
<html ng-app="app">
<head>
  <script data-require="angular.js@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>
<body >
 <div ng-controller="first">
    <button ng-click="cart1('test','test2')">transfer</button>
 </div>
 <div ng-controller="cart">
 <button ng-click="getData()">getStoredValue</button>
  {{cart2}}
 </div>
  
</body>
</html>

NOTE
Using $rootScope is not a recommended way to transfer variable across controllers, instead try using services.

