0

I'm new in Angular and I'm using ngRoute. Here is my routing:

var balaitus = angular.module('balaitus', ['ngAnimate', 'ngSanitize', 'ui.bootstrap','ngRoute']);
balaitus.controller('GlobalController', function ($scope) {

    $scope.isNavCollapsed = true; // Para que se colapse la barra

    $scope.selected_account = '';

});

balaitus.config(function($routeProvider){
    $routeProvider
        .when("/", {
            controller: "GestionCuentas",
            templateUrl: "gestion_cuentas.html"
        })
        .when("/cuentas", {
            controller: "GestionCuentas",
            templateUrl: "gestion_cuentas.html"
        })
        .when("/hastags_and_users", {
            controller: "HastagsAndPersonas",
            templateUrl: "hastags_y_personas.html"
        })
        .when("/estadisticas", {
            controller: "EstadisticasController",
            templateUrl: "estadisticas.html"
        });
});

Now I'm in the controller "GestionCuentas" and I want to change $scope.selected_account that is in the GlobalController. I have tried The most intuitive which is $scope.selected_account = newValue; but this didn't work. Also I have tried the same with $rootscope but this hasn't worked. How can I get this?

  • 1
    Without seeing how your HTML views are constructed, you could try `$scope.$parent.selected_account = newValue;`. I really dislike accessing scope properties like this, though, and would opt for a service to share values between scopes. – Lex Sep 01 '17 at 14:58
  • @Lex I found a solution [here](https://stackoverflow.com/questions/30926906/share-scope-data-between-states) and It worked! – Daniel Rueda Sep 02 '17 at 08:48

0 Answers0