It seems like I'm missing a key component here, as I keep encountering similar issues. There must be a fundamental gap in my understanding of Angular.
The scenario involves a controller:
angular.module('NextShift')
.controller('ContactsCtrl', ['$scope','contactFactory',
function($scope, $rootScope, Auth, $localStorage, $stateParams, contactFactory) {
console.log("I reach this point");
function getContacts() {
contactFactory.getContacts()
.success(function(contactList) {
console.log("Why am I not reaching this point?");
$scope.contacts = contactList;
})
.error(function(error){
console.log("Or here?");
$rootScope.error = "Failed to get contacts";
});
}
}
]);
Despite everything seeming to run smoothly without any apparent errors, my template remains empty and the console logs are void of any messages. My confusion deepens.
This is where my contactFactory comes into play:
angular.module('NextShift').factory('contactFactory', ['$http', function($http) {
var url = 'http://myurl.example/api/v1';
var contactFactory = {};
contactFactory.getContacts = function () {
return $http.get(url + '/contacts');
};
contactFactory.getContact = function(id) {
return $http.get(url + '/contacts/' + id);
}
contactFactory.updateContact = function(contact){
return $http.put(url + '/contacts/' + id, contact);
}
contactFactory.deleteContact = function(id) {
return $http.delete(url + '/contacts/' + id);
}
return contactFactory;
}]);
Something isn't clicking here. The console.log lines should be triggering at least... but they aren't. This situation is part of an Ionic Framework project, though I doubt that's the root cause.