I have two controllers/views, one called member.js which is for displaying a list of members projects:
.controller( 'MemberCtrl', function MemberCtrl( $scope,ProjectsService ) {
$scope.projects = [];
$scope.refresh = function() {
ProjectsService.query()
.then(function (data) {
$scope.projects = data;
});
};
$scope.refresh();
})
.factory('ProjectsService', ['$http', '$q', function($http, $q) {
return {
query: function() {
var deferred = $q.defer();
$http.get('/api/get-projects')
.success(function(data) {
deferred.resolve(data);
})
.error(function(data) {
deferred.reject(data);
});
return deferred.promise;
}
};
}])
The next controller is in add.js and handles creating a new project:
.controller( 'AddprojectCtrl', function AddprojectCtrl( $http,$scope,Session,$location ) {
$scope.addProject = function(project){
return $http
.post('/api/create-project', project)
.then(function (result) {
$location.path("/member");
});
};
})
The issue I have is that once i've added in the new project, $scope.projects on the MemberCtrl is out of date and doesn't show the newly added item. I guess I could use one controller for both actions but was wondering if this is the best approach or what the "anggular" way is?