# Access to $http inside DocView?

**URL:** <https://discuss.elastic.co/t/access-to-http-inside-docview/103715>\
**Category:** Kibana\
**Created:** [October 12, 2017, 11:52am UTC](https://discuss.elastic.co/t/access-to-http-inside-docview/103715 "2017-10-12T11:52:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlKnutsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlknutsen/32/22752_2.png) [@CarlKnutsen](https://discuss.elastic.co/u/CarlKnutsen)\
**Post date:** [October 12, 2017, 11:52am UTC](https://discuss.elastic.co/t/access-to-http-inside-docview/103715/1 "2017-10-12T11:52:27Z")

</div>

Hi there,

I'm trying to connect to a REST API out of a DocumentView in Kibana, cause I try to implement the functionality that developers are able to open tickets in our ticket system, when they are looking into the application logs. But I'm a newbie regarding Angular and therefore a little bit stuck trying to call the $http-service. I always get an error when trying to access $http. The code in the \*.js is the following:

```
import _ from 'lodash';
import angular from 'angular';
import { DocViewsRegistryProvider } from 'ui/registry/doc_views';
import templateHtml from './template.html';

DocViewsRegistryProvider.register(function() {
  return {
    title: 'Open ticket',
    order: 5,
    directive: {
      template: templateHtml,
      scope: {
        hit: '=',
        indexPattern: '='
      },
      controller: function( $scope ) {
        ........

        $scope.openTicket = function( $scope ) {
          $http.post('<URL>', '<TESTJSON>' ).
            then(function(response) {
                .....
            }, function(response) {
                .....
            });
        };
      }
    }
  };
});

```

This results in the following error during the call of openTicket():

> angular.js:14642 TypeError: Cannot read property 'post' of undefined  
> at Scope.$scope.openTicket (email.js:42)  
> at fn (eval at compile (angular.js:15500), :4:150)  
> at callback (angular.js:27285)  
> at Scope.$eval (angular.js:18372)  
> at Scope.$apply (angular.js:18472)  
> at HTMLFormElement. (angular.js:27290)  
> at HTMLFormElement.dispatch (jquery.js:4737)  
> at HTMLFormElement.elemData.handle (jquery.js:4549)

Can anybody help me, how I can make the HTTP-Service visible in function inside the controller?

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 12, 2017, 3:05pm UTC](https://discuss.elastic.co/t/access-to-http-inside-docview/103715/2 "2017-10-12T15:05:15Z")

</div>

Hey Markus,

`$http` is an Angular service, that you can inject into your service.  
You must basically just add it as a parameter to the function you pass to `register` and Angular will inject that service.

So your line 6 should look as follows:

```auto
DocViewsRegistryProvider.register(function($http) {

```

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![CarlKnutsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlknutsen/32/22752_2.png) [@CarlKnutsen](https://discuss.elastic.co/u/CarlKnutsen)\
**Post date:** [October 13, 2017, 7:24am UTC](https://discuss.elastic.co/t/access-to-http-inside-docview/103715/3 "2017-10-13T07:24:12Z")

</div>

Thank you very much, Tim. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 10, 2017, 7:24am UTC](https://discuss.elastic.co/t/access-to-http-inside-docview/103715/4 "2017-11-10T07:24:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
