It did a bad copy/paste in the example, it should read :
$scope.replaceQuery = function (searchName, $event) {
$event.stopPropagation();
if (TransactionsList.query !== searchName) {
TransactionsList.query = searchName;
TransactionsList.applyFilters();
The things is that the $digest is not started when my function execute, it will be triggered by the $apply of the ngClick directive after my function return, so it should be safe to not start it if there were a method for that.
I tried to used onclick and call $digest (further optimisation is that I need to run the $digest in case of changes only in the scopes subtree, so $scope.$digest instead of $roor.$digest is ok for my case) :
<span onclick="{{replaceQuery(tr.categoryName, $event)}}">{{tr.categoryName}}</span>
In the controller I have:
$scope.replaceQuery = function (searchName, $event) {
if ($event) {
$event.stopPropagation();
}
if (TransactionsList.query !== searchName) {
TransactionsList.query = searchName;
TransactionsList.applyFilters();
$scope.$digest();
}
};
But it does not work because the onclick expression is evaluated during a $digest so the call to $digest failed.
Anyway, maybe it is unecessary optimization as you suggest.
Thanks Peter for the answer,