For your case, it's better to look into typeahead directive and make max use of it.
http://angular-ui.github.io/bootstrap/#/typeahead
Instead of creating your own directive or service, you can use the existing directive with callback, typeahead-on-select
typeahead-on-select($item, $model, $label) (Defaults: null) :
A callback executed when a match is selected
This is the example that I created without using callback. It enables you to select a google address from what you type.
Without typeahead-on-select :
http://plnkr.co/edit/GMnzod9MQZWxsKSuJUJu?p=preview
The following is going step further by changing the selected address to uppercase. You can do whatever you want in this callback.
http://plnkr.co/edit/jaeSZdSKucMQgIF05KwD?p=preview
I used this function to change the selected address to uppercase.
$scope.myFunc = function($item, $model, $label) {
$scope.asyncSelected = $item.toUpperCase();
}
For your case you can make like the following
$scope.myFunc = function(category) {
if(category.id === $scope.ticketCategory.parentId) {
$scope.parent = category;
}
}
HTML
typeahead-on-select="myFunc($item)"
In summary, your use case and data might be different from the example that I used above, but the main approach is the same. There is a callback after you select an item, and you can manipulate your data control more with the callback typeahead-on-select.
TicketCategoriescollection and for a given id what data you want to be returned. there is an inconsistency in your question. You say " And I wanna assign a array to $scope.parent that equals $scope.ticketCategory.parentId" but in your code example you assign an object to it.