UPDATE
- Utilize Angular's service for better functionality.
- Ensure to set $scope.items in the callback function.
A big thank you goes out to Sylvain and Chen-Tsu Lin.
I am new to Angular and have a limited grasp on english. This question may seem rather elementary.
I am attempting to showcase a list of items when data changes, however, I am unable to see the list unless I initialize the items before running the code.
Here is the HTML code snippet:
<ul ng-controller="testController">
<li ng-repeat="item in items">{{item.description}}</li>
</ul>
And here is the corresponding JavaScript code:
function testControler() {
var items = []
var data = [{description: 'food'}, {description: 'fruit'}]
setTimeout(function() { items = data }, 2000)
$scope.items = item
}