I am currently working on a project using ui-router with angularjs. My goal is to create a template for a view that will display an image based on the specific view it is associated with. Below, I have provided an example state:
$stateProvider
.state('index', {
url: "",
views: {
"topStormtrooper": {
templateUrl: '/components/stormtroopers/stormtroopers.html',
controller: "stormtroopersCtrl"
},
"bottomStormtrooper": {
templateUrl: '/components/stormtroopers/stormtroopers.html',
controller: "stormtroopersCtrl"
}
}
})
My controller code is as follows:
.controller('stormtroopersCtrl', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) {
//
$scope.stormtrooper = $stateView; //I hope this works
}]);
Although the template remains the same, the image displayed should vary depending on the view it is loaded into. Currently, I have created separate controllers for each view and load the corresponding image. However, I believe it should be possible to achieve this using just one controller that can detect the specific view. While I am aware that you can identify the state, I am seeking a way to delve deeper and identify the view.
Any suggestions or ideas?