0

Consider the following simple autocomplete form:

<html>
...

<body>
...
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<input type="text" 
 ng-model="selected" typeahead="name for name in names | filter:{name: $viewValue} | limitTo:8" 
 typeahead-on-select='onSelect($item, $model, $label)'
 class="form-control">

You made this selection {{selection_made}}.
<!-- Run "run_me.sh {{selection_made}} on the server-->   

<!-- Render the image that run_me.sh saves to disk on the server --!>
<img ng-src=image.png/> 

</div>
<body>
</html>

Where the controller is defined elsewhere and is in charge of populating names and the definition of onSelect.

I would like to invoke a shell script on the server: run_me.sh with arguments {{selection_made}} and render the image that the server generates on the client.

How can I do this from angular + PHP ? Is there a lightweight approach to this?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • 1
    You could pass in the $http dependency and send an ajax request to the server from Angular. The web server on the other side would invoke the sh command and optionally return information or a status response. You can easily set up a "promise" similar to a call back in angular to handle the response. – JWP Dec 09 '14 at 23:54
  • Thanks. @JohnPeters I presume I could do this with `php`? What would a minimal example look like? – Amelio Vazquez-Reina Dec 09 '14 at 23:54
  • I'm not a PHP person, but as I understand it, PHP is a server side language / web server, and it must be able to handle inbound route requests and parameters being Posted or using Gets. So the answer is YES, the Angular client only need to send a POST and It could be asynchronous as well. – JWP Dec 09 '14 at 23:56
  • 1
    Take a look at this link. https://docs.angularjs.org/api/ng/service/$http – JWP Dec 09 '14 at 23:58

0 Answers0