It works when called via ui-sref
<a class="button" ui-sref="main.create">
but when it's called using ng-click and $stage.go, it's called and renders the page but my $urlRouterProvider.otherwise will override the DOM again. I noticed it when I debugged step by step. It maybe thinks that main.create is a non-existent url.
here is the code and function for ng-click.
<a href="#" ng-click="create()">Create Object</a>
and here is create() function
$scope.create = function() {
$state.go('main.create');
};
It's calling $state.go('main')
when ng-click="create()"
is used. But before it calls $state.go('main')
, I see the proper main.create page render in DOM. I wrote that "IF" statement to handle non-existent url so they get redirected back to main page. Here is my config.js.
.state('main', {
url: '/',
views: {
'@': {
templateUrl: 'app/main/main.html',
controller: 'MainController'
},
'content@main' : {
templateUrl: 'app/main/main.display.html'
}
}
})
.state('main.create', {
url: '/create',
views: {
'content@main' : {
templateUrl: 'app/main/main.create.html'
}
}
})
$urlRouterProvider.otherwise(function ($injector) {
var Session = $injector.get('Session');
var $state = $injector.get('$state');
if (Session.isAuthenticated()) {
$state.go('main'); // <-- this is what gets called when using ng-click and after main.create partial gets rendered
} else {
$state.go('login');
}
});