I'm trying to use a service call to update a results array that then gets used in an ng-repeat. On a form submit I call the necessary service and hookup my callbacks via .then() on the promise object. Unfortunately the view only gets updated once I start deleting the characters from the text input. It then displays the correct results.
Here is my view:
<div id="main" ng-controller="SearchController as searchCtrl">
<div class="header" >
<h1>Search and Add Tracks</h1>
</div>
<!--Search Bar-->
<form class="pure-form pure-g" novalidate ng-submit="searchCtrl.search()">
<div class="pure-u-1">
<input class="pure-input-1" type="search" placeholder="Search for tracks" ng-model="searchCtrl.query">
</div>
</form>
<!--Search Results Table-->
<div class="pure-u-1" >
{{searchCtrl.results.length}}
<div ng-repeat="track in searchCtrl.results" ng-include src="'templates/single-track-view.html'" >
</div>
</div>
</div>
And my controller code:
app.controller('SearchController',function(){
var searchCtrl = this;
searchCtrl.results = [];
searchCtrl.query = '';
this.search = function(query){
console.log(searchCtrl.query);
var processTracks = function(results){
console.log(results);
searchCtrl.results = results[0].tracks;
searchCtrl.results.push(results[1].tracks);
searchCtrl.query = '';
return results;
}
//search takes a DICTIONARY not a pure string
mopidy.library.search({"any": searchCtrl.query}).then(processTracks,console.error.bind(console));
}
});
When using the AngularJS inspector I can definitely see searchCtrl.results being updated within the scope with the correct results. The view simply will not update until I start removing characters.
EDIT: The result back from the promise is actually an array of responses. I'm calling an api from Mopidy (a music player), the array is the different responses from different music providers.