How to navigate from one tab to another tab by clicking a link or url in IONIC?

Suppose I have two tabs in my app, One is tab-one and another is tab-two now i want navigate from tab-one’s view(one.html) to tab tab-two’s view(two.html). I tried $state.go(), $location, $window.location but nothing works , I can navigate to any views successfully if all are under same tab even though the controllers are different, but navigation does not work if views belongs different tabs, following code shows states defined in app.js file

.state('tab.tasklist', {
    url: '/tasklist',
    views: {
      'tab-one@tab': {
        templateUrl: 'templates/one.html',
        controller: 'OneCtrl'
      }
    }
  })

.state('tab.ccpo', {
    url: '/ccpo',
    views: {
      'tab-two@tab': {
        templateUrl: 'templates/two.html',
        controller: 'AnotherCtrl'     
      }
    }
  })

This is definitively possible

1 Like

@mhartington That works great, but can this also be done with nested abstract and child states?

I don’t even really understand what you’re trying to do or why you’re doing it in an ancient thread about a totally different version of the framework, but there’s virtually never any reason to do direct DOM access in an Angular app, let alone using undocumented internal element IDs. If you have to grab an element, use @ViewChild.

Just sharing a solution to the problem… I’m not expert yet on all parts of Angular… I will learn about @ViewChild later I guess…

Anyway, can you please explain if it’s bad and why the way I did to access DOM and trigger the click event? Side effects?

Yes.

Some security concerns are documented here. There are also futureproofing issues - by using only Angular, you ensure your app would work even on a platform that doesn’t allow direct DOM access (or even have a DOM). Also, it’s extremely brittle to rely on internal framework implementation details (like element IDs). They can change at any time without warning or notice, and all of a sudden your code breaks.

I wish I understood better what the problem of this thread actually was, in which case maybe I could suggest some other things to do with your code.

In any event, any time you feel the urge to even type the word document in an Ionic app, I would urge you to stop and look for a more idiomatic and solid way to achieve your core goal.

1 Like

Thank you! I removed my answer for the sake of security. cheers :slight_smile: