How to redirect one controller to other controller after onclick on button?


#1

Hi All,

I want to redirect listing to description with out using href. How can redirect?? Can any one help me??


#2

I am trying to use window.location="#/app/players/6" it is working first time but not second time…


#3

You could use the $state service in angular.

$state.go("tab.friends");

Don´t forget to include the $state service into your controller. You could put the above code into a method call goToSite(). Then you could call that method onClick with ng-click.

Hope this helps


#4

Thanks…for reply…

I want to go friend detail page how i can redirect using $state object???


#5

Just change “tab.friends” with the aquivalent state of your detail page. e.g. “detailFriend”


#6

You would use something like ng-click="goToFriendDetail()" attribute in the clickable item where the function would be defined in your controller like:

$scope.goToFriendDetail = function() {
  $state.go('friend.details');
};

You would define a state for friend.details in your routing rules in app.js.


#7

You are discussing different… i want different… :slight_smile:
friends page content list of friends … On click on any friend list item . it should open that friend detail.
That miens each friend have id and it will redirect as per the id…ok …
In that case, how can use $state.go…


#8

Hi shashikant,

maybe this is what you need: http://ionicframework.com/docs/api/directive/ionNavView/

I use it to display a user profil after click on a list with users.

regards
mav


#9

Thanks…
I know the redirection usign href…
but i want to do $state.go .


#10

Then like this:

$state.go("friendDetail", {
                "friendId": $scope.friendId
            });

#11

So define a state for the detail screen something like this:

$stateProvider.state('friend.details', {
    url: '/friend/detail/:id',
    templateUrl: 'templates/friendetail.html',
    controller: 'FriendCtrl'
    })

See http://learn.ionicframework.com/formulas/navigation-and-routing-part-1/


#12

Thanks …for reply…
I know Using $stateProvider. But i want to redirect List to detail from controller.

Ex-
If there is a button on list page. Onclick on button it should open 5th product detail. How we can use…??
Using javascript it is working…
JavaScript ex- window.location = “#/app/lists/5”;

but i want to do using angular js/Ionic. How can i do ???


#13

Not sure what the ‘problem’ is. You can either use an ng-click attribute specifying a function that changes state (example above), OR you can use ui-sref attribute an any element if you have named states defined. Both do the same thing, either way, you are telling the app to transition from one state to the next.