1
I looked for how to share a Scope between two controllers, and I saw that one option would be service or a Factory using the Singleton standard, but I’ve tried both and what happens is that I can’t set the value of a controller to another, in the example below I wanted you to print example.com.br but it’s 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
}
});
Upshot
It’s not updating yet, is it because I’m using the js separate from the app.js for the controllers? I’ll take a look, sometimes I’m eating ball, but it’s returning {} now
– Gabriel Becher