I want to create a simple real-time search with angularjs client side, and java server side, i want to use the similar effect than onKeyUp in dom and ajax but in angular js,
<div ng-app="MyModule" ng-controller="MainCtrl">
<input class="form-control field span12" id="objctf" rows="4" ng-model="keywords" />
<a href="/adminpanel?q=" class="btn btn-primary">Manage</a>
<div>
<p ng-show="loading">Loading...</p>
<p ng-hide="loading">Response: {{response}}</p>
<p ng-hide="loading">writed: {{keywords}}</p>
</div>
</div>
var MainCtrl = function($scope, $http) {
$scope.keywords = "debut";
alert ('en mode ajax '+$scope.keywords);
$scope.response = $http.post('/api/member/getuser', { "username" : $scope.keywords });
};
Replace .then by .success and .error ;) @jack
Add ng-change to your input like so:
Create a method to handle the change on the controller:
Finally, create a service to make the call to the server:
Handling things in this fashion, you'll gain a re-usable search method whose results can be persisted through routes if needs be.