0

so I have this code which displays data from elastic search, the purpose is to get some data, compute a average and display a red or green button.

I'm just starting.

<!doctype html>
<html ng-app="EsConnector">
<link rel="stylesheet" href="styles/main.css">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.js"></script><!-- // a recuperer -->
    <script src="scripts/controllers/elasticsearch.angular.js"></script>
    <script src="scripts/controllers/es_connect.js"></script>
  </head>
  <script type="text/javascript">
   function addTpsGeocodage(p1) {
           alert(p1);
       }
  </script>
  <body>
        <title>Dashboard</title>

       <h1 align="center">Dashboard </h1>
      <hr>
       <h3>Services Externes</h3>
    <div ng-controller="QueryController">

    <div >
        <table>
          <tr ng-repeat="item in hits">
          <td>
          {{item['_source']['tpsGecodage']}}
         <script>
         addTpsGeocodage(item['_source']['tpsGecodage']);
        </script>
          <span class="green_circle" ng-if="item['_source']['tpsGecodage'] < 1">
                     <a href="kibana link">Lien </a> 
               </span>
             </td>
              </tr>
        </table>
       </div>
    </div>
    <br>
    Above this line ^^^  should be the results of a test search on the ElasticSearch server.
  </body>
</html>

Basically this addTpsGeocodage(item['_source']['tpsGecodage']); (line 29) is doing nothing.

How can I pass a variable from the angular JS scope to the javascript scope.

Thanks

2
  • What are you trying to do with that function? Basically, why you want to execute addTpsGeocodage in that way? Commented Nov 19, 2015 at 11:22
  • Why don't you put the function in the controller? Commented Nov 19, 2015 at 15:06

1 Answer 1

0

Assign the function to a variable so that it can be accessed globally.

  <script type="text/javascript">
   var addTpsGeocodage =  function(p1) {
           alert(p1);
       }
  </script>

Now, you can access addTpsGeocodage anywhere.

Sign up to request clarification or add additional context in comments.

2 Comments

But I can call my function anywhere, it's just that the javascript cannot access the value of item['_source']['tpsGecodage']
Then the item['_source']['tpsGecodage'] should be undefined. What is the o/p for {{item['_source']['tpsGecodage']}}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.