This could be because readFile
is asynchronous. Try something like this:
.service('tagList', function($q) {
var d = $q.defer();
this.getTags = function() {
fs.readFile('tags', 'utf8', function(err, data) {
if (err) throw err;
console.debug(data.split(','));
d.resolve(data.split(','));
});
return d.promise();
};
})
and then use it like this:
.controller('sidebarCtrl', function($scope, tagList) {
tagList.getTags().then(function(tags){
$scope.tags = tags;
});
})