One way you can do it if you dont want to create the service, but i think you should!! you can set the ng-click to hande clicing on the tab and then set the stateParameter programatically
Iām a newbie in Ionic (and Angular) and struggled with this issue. I think what snailred is asking about is how you pass in a parameter so that the tabs use the parameter in their navigation. For experienced Angular coders, this might be obvious but I personally struggled with this. This is what I finally figured out, which seems to work great. If itās wrong or should be done in a different way, I would love to get some feedback.
The key is to attach a controller to the abstract state and assign the parameter to the scope. Note that I only have one controller attached to the abstract tab view which assigns url_id to the scope. I posted this on codepen but for your reference, here is the simple script:
<ion-nav-bar class="nav-title-slide-ios7 bar-positive">
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
<script id="tabs.html" type="text/ng-template">
<ion-tabs class="tabs-icon-top tabs-positive">
<ion-tab title="Home" icon="ion-home" href="#/tab/{{url_id}}/home">
<ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>
<ion-tab title="About" icon="ion-ios7-information" href="#/tab/{{url_id}}/about">
<ion-nav-view name="about-tab"></ion-nav-view>
</ion-tab>
</ion-tabs>
</script>
<script id="landing.html" type="text/ng-template">
<ion-view title="Landing">
<ion-content class="padding">
<h2>Landing Page</h2>
<input ng-model="urlId" placeholder="enter in an id">
<a ui-sref="tabs.home({ id: urlId })">go to tabbed view</a>
</ion-content>
</ion-view>
</script>
<script id="home.html" type="text/ng-template">
<ion-view title="Home">
<ion-nav-buttons side="left">
<a class="button button-icon icon ion-ios7-arrow-back" href="/#/landing">Landing</a>
</ion-nav-buttons>
<ion-content class="padding">
<h2>Home Page</h2>
<p>Notice that the id in the URL is {{ url_id }}. Click the <b>about</b> tab to see this preserved!</p>
</ion-content>
</ion-view>
</script>
<script id="about.html" type="text/ng-template">
<ion-view title="About">
<ion-content class="padding">
<h2>About Page</h2>
<p>Notice that there are no controllers for either the about or home view! I only have a controller
for the abstract tab view where I assign the $stateParams url id ($stateParams.id) to the scope ($scope.url_id) and since the <b>home</b> and <b>about</b> views are SUBviews, they inherit that scope variable.
</ion-content>
</ion-view>
</script>
Hope that helps and if anyone has any comments, please let me know!
PS - For some reason my demo on CodePen opens a new tab when I click links. The CodePen demos I saw from Ionic didnāt do this and I couldnāt figure out why. Does anyone have an answer?
Iām passing parameters ok between tabs, using a factory like
angular.module('myApp.services', [])
.factory('myService', function () {
return {
data: {
id: '',
name: ''
}
// Other methods or objects can go here
};
});
My first tab has a list and when you click on an item it fires a state.go and takes you to the second tab.
he first time the second tab is rendered it sets the id and name ok, and I render some css background images based on their value. The next time a selection from the first time is made, the controller isnāt triggered and the view doesnāt refresh.
How can I force this please? I have tried half a dozen different ways and none have been that successful.
the cache false works, when you are going into a level 3 deep nested state (Thanks Iāve been having a headache with this)
this forces the OID to reset everytime the tabs abstract state is accessed, without this the ID would be the same everytime, (this is what cause my headache).
ui-sref="tabs-organisations.info({OID: id})"
and then you can just call any tab state with ui-sref