I've read many questions like this but for some reason haven't found why my code isn't working.
The goal is to have the page load with a list of items loaded by ng-repeat, which works fine, but then when the user performs a function, have that ng-repeat array replaced with another one of the same structure. It's got through http.
The code is like this.
// in HomeController
$scope.content = {
items: [ {
title: "hi!"
} ]
}
$scope.search = function() {
if ( $scope.query == '' )
return $scope.content = null
$http
.get( '/api/search', { params:
{ terms: $scope.query }
} )
.success( function ( results ) {
console.log( results)
$scope.content.items = results
})
.error( function ( error ) {
$flash.error = error
})
}
then
// in the HTML
<div ng-controller="HomeController" class="list-container">
<div class="panel panel-item" ng-repeat="item in content.items">
<h2 ng-bind="item.title"></h2> // ... etc
Then elsewhere there is an ng-change that triggers search(). I know the http.get works because I see it in the console. But it doesn't update the main source of ng-repeat or even the scope, from the looks of it.
Is it relevant if this controller is nested in another one?
$httpreturns a list which contains duplicates, you have to alterng-repeatlike:ng-repeat="item in content.items track by $index"