Hi guys,
I need to reference a scope from other controller, when working with a
modal, the way a did it is as follow:
the SearchController, that is the controller used by the modal, needs to
reference the EntityController scope.
angular.module('app').controller('EntityController', ['$scope',
'$state', '$http', '$modal', function ($scope, $state, $http, $modal) {
$scope.showDialog = function () {
searchDialog = $modal.open({
templateUrl: 'app/partials/search-form.tpl.html',
controller: 'SearchController',
backdrop: true,
resolve: {
searchCaptcha: function(){
return
$http.get('/index.php').then(function(response){
return response.data.captcha;
});
},
entitiesScope: function(){
return $scope; /*resolving entities scope to be
used in SearchController.ok function*/
}
}
});
};
}]);
angular.module('app').controller('SearchController', ['$scope',
'searchCaptcha', '$http', 'entitiesScope','$modalInstance', function
($scope, searchCaptcha, $http, entitiesScope, $modalInstance){
$scope.captchaSrc = searchCaptcha;
$scope.pesquisaCnpj = {};
$scope.ok = function(){
$http.post('/index.php',$scope.search).then(function(response){
entitiesScope.entity = {
razao : response.data.empresa.nome_empresarial,
fantasia : response.data.empresa.nome_fantasia,
};
});
$modalInstance.close();
};
}]);
It is working, but I want to know if it is the best way to do.
Tnks.
--
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.