Use the ng-submit directive on your form and make it trigger a function that simply:
- executes the query in
queryController.queryCode
- retrieves the result and stores it in
queryController.results
The binding you've done in your html between that result variable and your table content is sufficient for your page to be updated as soon as queryController.results changes, without you doing anything else.
Here's an example of what your html code could look like:
<div ng=controller="QueryController as queryController">
<form ng-submit="queryController.executeQuery()"> <!-- used ngSubmit here -->
<input type="text" ng-model="queryController.queryCode"/>
<input type="submit" value="Query"/>
</form>
<table>
<tr ng-repeat="row in queryController.results">
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
</tr>
</table>
</div>
... and the additional code in your controller:
...
queryController.executeQuery = function() {
// pseudo-code that executes your query and gives you back a promise
var promise = database.query(queryController.queryCode);
promise.then(function (resultSet) {
queryController.results = resultSet;
});
};
...
EDIT:
Since you mentioned that you execute your query via an http request, here is a link to the AngularJS way to do so.
TL;DR:
Assuming you're using the http POST method to execute your query:
$http.post(/*your database server URL*/, JSON.stringify(queryController.queryCode))
.success(function(data) {
// this callback will be called asynchronously when the response is available
queryController.results = JSON.parse(data);
});
Please note that you'll also need to serialise/deserialise your data to transfer it through http. I did so in my example, featuring a simple way to parse and write using the JSON format.