As a newcomer to AngularJs, I am still grappling with the basics. Currently, I am using the Soundcloud API to retrieve a list of followers for a specific user. In my $scope.init function, I have managed to establish a connection with Soundcloud, authenticate a user, and obtain a JSON list of the user's followers. These followers are then pushed into an array named $scope.results, and I validate the array by displaying it in the console. However, when attempting to display each follower as a list item in the array using ng-repeat in my main.html view, I encounter issues... Here is the relevant code:
main.js
.controller('MainCtrl', function ($scope, $http) {
$scope.apiKey = "##########################";
$scope.results = [];
$scope.init = function(){
SC.initialize({
client_id: $scope.apiKey,
redirect_uri: "http://localhost:9000/callback.html"
});
// initiate auth popup
SC.connect(function() {
SC.get('/me', function(me) {
alert('Hello, ' + me.username);
});
SC.get('/me/followers', function(followers) {
angular.forEach(followers, function(follower, index){
$scope.results.push(follower);
});
console.log($scope.results);
});
});
main.html // which is a view
<div ng-init="init()">
<li ng-repeat="follower in results">
<div class="row-fluid">
<div class="span3">
<div class="span6">
<h3>{{follower.username}}</h3>
<p>{{follower.description}}</p>
</div>
</div>
</div>
</li>
</div>
index.html
<!doctype html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="styles/bootstrap.css">
<link rel="stylesheet" href="styles/main.css">
</head>
<body ng-app="soundSelectApp" ng-controller="MainCtrl">
<div class="container" ng-view></div>
<script src="components/angular/angular.js"></script>
<script src="components/angular-resource/angular-resource.js"></script>
<script src="components/angular-cookies/angular-cookies.js"></script>
<script src="components/angular-sanitize/angular-sanitize.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>