Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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

share|improve this question
    
it's not really clear what your issue is here. This appears to be functional code, but to verify the results we would need to know what the server response is for the various values. nothing here stands out as being out of place. – Claies Jul 1 at 17:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.