I currently have an input text field displayed in my view:
<input type="search" placeholder="Search" ng-model="search.$">
This input field acts as a filter for the list of items displayed:
<a ng-repeat="item in items | filter:search" href="#">{{item.name}}</a>
The reason I use search.$
is to enable searching through all properties of the object item
.
Now, I am looking to set the input value programmatically from the controller whenever needed:
angular.controller('MyCtrl', function ($scope) {
var query;
$scope.updateSearchQuery = function () {
//query is populated from another source, service, http provider...
$scope.search = query;
});
However, even though this new query
filters the list, it does not display in the input field.
I've attempted using $scope.apply
without success:
...
$scope.$apply(function() {
$scope.search = query;
});
...
UPDATE: Another method I tried was:
$scope.search.$ = query;
You can find a demonstration here: http://plnkr.co/edit/CwzsrJxU9Kb9AARVcENT?p=preview
Can you identify what I might be overlooking or missing?