So I'm making an app in Ionic and it contains some basic dynamic text from online admin site. I've managed to get this data into app trough json and now I'd like to create dynamic links (or states) in my app. The thing is that I have a list of some substances and each of that substances contains different info. So right now I have a list of these substances and when I click on a specific substance I'd need it to go to a different state, which would show all the info of this specific substance.
Here's the code that I have so far:
database:
substances: [
{
sID: 'int',
sTITLE: 'Some title 1',
sINFO: 'some info 1',
},
{
sID: 'int',
sTITLE: 'Some title 2',
sINFO: 'some info 2',
},
.....
]
app.js
.state('substances', {
url: "/substances",
templateUrl: "templates/substances.html",
controller: 'SubstancesCtrl'
})
.state('substanceDetails', {
url: "/substanceDetails",
templateUrl: "templates/substanceDetails.html",
controller: 'substanceDetailsController'
})
controllers.js
.controller('SubstancesCtrl', function ($scope, $stateParams, $rootScope, $http) {
$http.get('http://someurladdress.php?type=json')
.success(function (data) {
$scope.substances = data;
})
.error(function (response) {
$scope.message = "Error";
});
})
substances.html
<ul class="list">
<li ng-repeat="sID in substances" class="item ">
<a ui-sref="substanceDetails({sID:substances.sID})">
{{sID.sTITLE}}
</a>
</li>
</ul>