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

```
You could use angular's services. Basically you need to create the service as below

```
app.service('svc', function() {
  this.k = "";
  this.setK = function(value) {
    this.k = value;
  }
  this.getK = function() {
    return this.k;
  }
});

```

Then make sure to inject the service to your controller

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

```