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?

4
  • 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. Commented Dec 9, 2014 at 23:54
  • Thanks. @JohnPeters I presume I could do this with php? What would a minimal example look like? Commented Dec 9, 2014 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. Commented Dec 9, 2014 at 23:56
  • 1
    Take a look at this link. docs.angularjs.org/api/ng/service/$http Commented Dec 9, 2014 at 23:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.