I have a button that switches between admin and client mode. I laid it on the root crop so that I could access it everywhere.
I use angular-ui directiveto switch.
I set the watch on this model. But nothing happens. Any idea what could be wrong?
.run(['$rootScope', '$state', '$stateParams', '$location',
function ($rootScope, $state, $stateParams, $location) {
$rootScope.projectMode = 'Client';
$rootScope.$watch('projectMode', function(){
var path = $location.path();
alert("fire")
if($rootScope.projectMode === 'Client'){
var current = 'client'
var replace = 'admin'
} else {
var current = 'admin'
var replace = 'client'
}
var newUrl = path.replace(current, replace)
$location.url(newUrl);
})
}])
Here is my view.
<div class="btn-group">
<button type="button" class="btn btn-default" ng-model="projectMode" btn-radio="'Client'">Klient</button>
<button type="button" class="btn btn-default" ng-model="projectMode" btn-radio="'Admin'">Admin</button>
</div>
btn-radio is the angular -ui directive for switching.
I checked that is $rootScope.projectModechanging. Therefore, there $watchmust be something wrong with it.
source
share