I am trying to display the initial values from array of object on my template by default, when I navigate to lets say, session/1 or session/2 and so on, I can see the data getting display, but I need to figure out a way to display initial values on the first session/01
This is app file:
angular
.module('App', [
'ngAnimate',
'ui.bootstrap',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function ($routeProvider) {
$routeProvider
.when('/session/:id', {
templateUrl: 'views/session.html',
controller: 'SessionCtrl',
resolve: {
SomeData: function( $route ) {
return $route.current.params.id;
}
}
})
.otherwise({
redirectTo: '/session/1'
});
});
These are my controllers:
angular.module('App')
.controller('HeaderCtrl', function ($scope, $location, sessions) {
sessions.getSessions().success(function(data) {
$scope.survey = data.survey_response;
$scope.survey_properties = $scope.survey.properties;
$scope.survey_dates = $scope.survey.dates;
$scope.sections = $scope.survey.sections;
$scope.section = $scope.survey.sections[0];
});
$scope.getSession = function(session) {
$scope.section = session.section;
console.log($scope.section, 'section from HeaderCtrl');
$scope.session_number = session.section.session_number;
console.log($scope.session_number, 'section number');
};
});
angular.module('App')
.controller('SessionCtrl', function ($scope, SomeData, sessions) {
sessions.getSessions().success(function(data) {
$scope.survey = data.survey_response;
});
});
angular.module('App')
.controller('FooterCtrl', function ($scope, $location) {
$scope.nextSession = function(section) {
$scope.sectionId = section.session_number;
var path = 'session/' + ($scope.sectionId + 1);
$location.path(path);
};
$scope.prevSession = function(section) {
$scope.sectionId = section.session_number;
var path = 'session/' + ($scope.sectionId - 1);
$location.path(path);
};
});
And this is my html template for the sessions:
<li class="list-group-item p-a-0" ng-repeat="x in section.feedback_bucket">
<h4 class="list-group-item-heading lead">{{x.rating_question}}</h4>
</li>
The data desired to display on session/1 is:
$scope.section = $scope.survey.sections[0];
From HeaderCtrl