My html is this:
<body ng-controller="MainCtrl as ctrl" class="bodyContainer">
<div ng-repeat="stuff in ctrl.stuffies">
here
</div>
This is my controller:
angular.module("AuthenticationApp", ["BaseApp"])
.controller("MainCtrl", ["$http", "$window", "BaseService", function($http, $window, BaseService) {
var self = this;
BaseService.fetch.stuffs(function() {
self.stuffies = BaseService.stuffies;
console.log(self.stuffies);
self.cerrorMessages = BaseService.cerrorMessages;
});
}]);
And this is my BaseApp:
angular.module("BaseApp", [])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}])
.config(['$locationProvider', function($locationProvider){
$locationProvider.html5Mode(true);
}])
.factory("BaseService", ["$http", "$window", function($http, $window) {
var self = this;
/* All functions which call fetch should have a callback function
* on the front-end which sets
* 1) a variable (i.e. stuffies etc.)
* 2) and BaseService.cerrorMessages. */
self.fetch = {
stuff: function(callback) {
$http.get("/stuffs/")
.then(function(response) {
self.stuffies = response.data;
callback();
}, function(response) {
self.accessErrors(response.data);
callback();
});
}
};
The problem is, even though it logs an item inside self.stuffies (when this line is run: console.log(self.stuffies);), here is not printed in the HTML. There doesn't seem to be anything inside ctrl.stuffies. I tried moving console.log(self.stuffies); outside of BaseService.fetch.stuffs(function() and it logs undefined. How do I get ctrl.stuffies to be BaseService.stuffies?