I tried to share a scope between two controllers , and I saw that one option would be the service or a factory > that use the singleton pattern, but I have already tried both and what happens is that I can not set the value of a controller to another, in the example below I wanted it to print example.com. br but is printing test .
First controller
app.controller('ctrRelatorioBolsaPorOrientador', ['$scope','$http', '$filter', '$routeParams', 'PropriedadesCompartilhadas',function($scope, $http, $filter, $routeParams, PropriedadesCompartilhadas) {
$scope.url_grafico = 'exemplo.com.br';
PropriedadesCompartilhadas.set($scope.url_grafico);
}
Second controller
app.controller('ctrRelatorioBolsaPorOrientadorPdf', ['$scope','$http', '$filter', '$routeParams', 'PropriedadesCompartilhadas',function($scope, $http, $filter, $routeParams, PropriedadesCompartilhadas) {
$scope.url_grafico = PropriedadesCompartilhadas.get();
}
app.js (factory)
var app = angular.module("sicite", ["ngRoute", "ngAnimate", "ngSanitize", "ui.bootstrap", "ngPasswordMeter", "angular-loading-bar", "googlechart"]);
app.factory('PropriedadesCompartilhadas', function() {
var valor = 'teste';
function set(data) {
valor = data;
}
function get() {
return valor;
}
return {
set: set,
get: get
}
});
Result