Currently, I am developing an angular application that connects to a Rails backend and interacts with the database through API calls to receive JSON objects. My challenge lies in defining multiple scoped variables within a controller. At the moment, I have a variable called markets which holds all market data from the database - essentially serving as the index. However, I am facing difficulty accessing a single market for the show page. Initially, I had two separate controllers, but it didn't feel like the right approach.
Any help or guidance on this issue would be greatly appreciated!
Listed below are the routes:
angular.module('farmCart', ['ui.router', 'templates'])
.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
// Route configurations
},
]);
A snippet from the Markets Factory:
angular.module('farmCart')
.factory('markets', [
'$http',
function($http) {
// Factoring logic for fetching markets
},
]);
Snippet from the Markets Controller:
angular.module('farmCart')
.controller('marketsCtrl', [
'$scope',
'markets',
function($scope, markets) {
// Controller logic for handling markets
},
]);