Currently in my angular project, I am utilizing Angular.js material. I am trying to display a $mdialog
with a custom controller, where the user can modify some data and have those changes applied to my $scope
variable. This is an example of what I am doing at the moment:
function myControllerFn($scope, MyService){
// I am making a copy of my service variable to avoid altering it until the user clicks on the save button
$scope.name = angular.copy(MyService.name);
$scope.editCurrentProfile = function() {
$scope.showEditProfileDialog($scope.name).then(function(name){
$scope.name = name;
}
}
$scope.showEditProfileDialog = function(name) {
var deferred = $q.defer();
$mdDialog.show({
controller: 'editProfileViewCtrl',
templateUrl: 'controllers/editProfileDialog.tmpl.html',
locals: {
name: name,
deferred: deferred
}
});
return deferred.promise;
};
}
Subsequently, in the dialog controller, I have:
function editProfileViewCtrl($scope, name, deffered) {
deferred.resolve('newName');
}
However, I believe this method may not be the most efficient. Therefore, what is the optimal way to communicate between two view controllers in angular without the need for a new service? Or would it be better to create another service, such as EditDialogService
, where the results can be saved?