Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

In my Angular controller, I am using 3 different functions to get the data. It works fine, but is there a way to simplify this?

"use strict";

angular.module("tcpApp")
.controller("projectSummaryController", 

    ['$scope', '$routeParams', '$location', 'server', 'modalService', '$q',

    function ( $scope, $routeParams, $location, server, modalService, $q ) {


        $scope.projectId = $routeParams.projectId;
        $scope.subProjectId = $routeParams.subProjectId;
        $scope.phaseId = 0;
        $scope.disciplineId = 0;
        $scope.contractorId = 0;

        $promise1 = 



        $scope.queryConractorInfo = function ( contractorId ) {


            server.contractorInfo.get({

                projectId:$scope.projectId, 
                subProjectId : $scope.subProjectId,
                contractId : $scope.contractorId,
                disciplineId : $scope.disciplineId,
                staticId : 0 /* at present static */

            }).$promise.then(function ( contractorInfo ) {

                $scope.contractorInfo = contractorInfo;


            })


        }


        $scope.queryConractorList = function ( phaseId, disciplineId ) {

            server.contractorsList.query(
                {
                    projectId:$scope.projectId,
                    subProjectId : $scope.subProjectId, 
                    phaseId : phaseId, 
                    disciplineId: disciplineId

                }).$promise.then(function ( contractorsList ) {

                    $scope.contractorId = contractorsList[0].Id; //setting the first contractor as default;

                    $scope.queryConractorInfo( $scope.contractorId ); 3rd function



                });

        }

        $scope.queryProject = function ( prjId, subPrjId ) {

            server.projectSummary.get({id:$scope.projectId})

            .$promise.then(function (data) {

                //only setting phase id and desciple id to get list of contractors

                $scope.phaseId = data.PhaseIds[0].Id; //setting the first phase as default;
                $scope.disciplineId = data.DisciplineIds[0].Id; //setting the first descipline as default;

                $scope.queryConractorList( $scope.phaseId, $scope.disciplineId ); //second function


            });

        }

        if($scope.projectId) {

            $scope.queryProject(); //first function

        }

    }]);
share|improve this question

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.