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: 
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)**
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

```