I have a piece of code where I call $location.path(name) and nothing seems to happens (at first). I can call console.log($location.path()) and it does show the new path -- but the view doesn't change.
Chain of events (some asynchronous): I have two controllers (and matching views), MainCtrl and CpugraphCtrl, and a Service GetDataService and one external data API (Google).
button in Main view calls
function in MainCtrl that calls
function in GetDataService that calls
google client API gapi.client.load() with a callback to
function in GetDataService, which uses $rootScope.$broadcast('GraphUpdate',..);
in MainCtrl, $scope.$on('GraphUpdate',function() {..}) calls
$location.path('cpuGraph');
I can verify (mentioned above) that all the pieces go -- but the view doesn't re-render. If I click the button a second time, it does chnage views and re-render using my CpugraphCtrl. If I call $scope.$apply() right after $location.path() it also re-renders (sometimes) but also sometimes reports (on the console) an error in angular.js....
Should I be calling $scope.$apply() somewhere else?
--- edit -- adding route config --
angular.module('analytics2App', [
'ngResource', 'googlechart'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/cpuGraph', {
templateUrl: 'views/cpuGraph.html',
controller: 'CpugraphCtrl'
})
.otherwise({
redirectTo: '/'
});
});