Olli Olli - 2 months ago 37
AngularJS Question

$state.go and $state.otherwise malfunction

I'm trying to go to a page(template) using

$state.go
.

Controller

.controller('NavCtrl', function($scope, $location, $state) {
$scope.openDaily = function() {
$state.go('daily');
};
})


It works but for only a millisecond or something as it's redirected BACK to the
'/select'
page because the
$state.otherwise
says so.

app.js

.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('select', {
url: '/select',
templateUrl: 'templates/select.html',
controller: 'selectController'
})
.state('daily', {
url: '/daily',
templateUrl: 'templates/daily.html',
controller: 'dailyController'
});
$urlRouterProvider.otherwise('/select');
})


What is causing this please?

UPDATE

index.html

<body ng-app="starter" animation="slide-left-right-ios7">
<ion-nav-view>
</ion-nav-view>
</body>


select.html

<ion-view title="Select" ng-controller="NavCtrl">
<ion-content>
<div class="list-card" ng-click="openDaily()">
<a href='#' class="item item-icon-left">
<i class="icon ion-home"></i>
Personal
</a>
</div>
</ion-content>

<div class="bar bar-footer bar-balanced">
<div class="title">Add File/Folder</div>
</div>


</ion-view>


and daily.html(template):

<ion-view title="Select" ng-controller="NavCtrl">
</ion-view>


Using Ionic Framework.

Answer

Please remove href='#' from <a> tag. Because this will call default state(Here it is select state).

Comments