Question: i am trying to access the variable "k" from out side the $scope function 

```
  .controller('AboutCtrl', ['$scope','$http', function($scope,$http) {
  var k ="";
  $scope.search = function() {
    // $scope.searchText will give the search terms
    k = $scope.searchText;
    console.log(k); //has something
  };
  console.log(k); // this is empty

```

Answer: 
Use $rootScope for this, rootScope is a globle variable in angular, you need to just inject dependency as you can see in below code and use it outside controller as well..

```
.controller('AboutCtrl', ['$scope','$http','$rootScope'  function($scope,$http,$rootScope) {
     // var k =""; use below method.
    $rootScope.k = "";
      $scope.search = function() {
        // $scope.searchText will give the search terms
        $rootScope.k = $scope.searchText;
        console.log($rootScope.k); //has something
      };
      console.log($rootScope.k); // this is empty

```
It will be empty until you really call `search` function,

```
app.controller("AboutCtrl", function($scope, $http) {
  var k = "";
  $scope.search = function() {
    // $scope.searchText will give the search terms
    k = $scope.searchText;
    console.log(k); //has something
  };
  //this will print the value
  $scope.print = function() {
    alert(k);
  }

});

```

**[DEMO](https://plnkr.co/edit/Qg99qm87dELV89fbN4ZP?p=preview)**