0

Im trying to add another function to my controller but it keeps breaking the controller.

here is my code:

.controller('ClimbController', [
	'$scope', '$stateParams', 'Climbs', function(
	$scope, $stateParams, Climbs) {

		var climb_id = $stateParams.climbId;
		var areaId = $stateParams.areaId;

		if (!isNaN(climb_id)) {
			climb_id = parseInt(climb_id);
		}

		if (!isNaN(areaId)) {
			areaId = parseInt(areaId);
		}

		$scope.selected_ = {};
		$scope.items = [];
		$scope.details = true;
		// looping though all data and get particular product
		$scope.selectClimb = function(areas){
			areas.forEach(function(data) {
			    if(data._id == climb_id){
			    	$scope.selected_ = data;
			    }
			});
		}
		// get all posts // try some function to get a single produt from server
		$scope.getPosts = function(){
			Climbs.getPosts()
			.success(function (data) {
				// data = feed.json file

				var climbs = [];
				data.areas.map(function(area) {
					if (area._id === areaId) {
						climbs = area.climbs;
					}
				});
				$scope.selectClimb(climbs);
			})
			.error(function (error) {
				$scope.items = [];
			});
		}
		$scope.getPosts();
}
])

And I ned to add this to it:

.controller('MyCtrl', function($scope, $ionicModal) {
  $ionicModal.fromTemplateUrl('test-modal.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  });
  $scope.openModal = function() {
    $scope.modal.show();
  };
  $scope.closeModal = function() {
    $scope.modal.hide();
  };
  //Cleanup the modal when we're done with it!
  $scope.$on('$destroy', function() {
    $scope.modal.remove();
  });
  // Execute action on hide modal
  $scope.$on('modal.hidden', function() {
    // Execute action
  });
  // Execute action on remove modal
  $scope.$on('modal.removed', function() {
    // Execute action
  });
});

When I try to add this to the code it breaks it. I nee to either add it as another function or whatever is needed to add it to the code.

Thanks so much

1
  • what breaks ?? you want to include Myctrl all functions into above controller? Commented Sep 23, 2016 at 18:20

1 Answer 1

1

Assuming that you want to merge 'MyCtrl functions into ClimbController then

.controller('ClimbController', ['$scope', '$stateParams', 'Climbs','$ionicModal', function($scope, $stateParams, Climbs,$ionicModal) {

        var climb_id = $stateParams.climbId;
        var areaId = $stateParams.areaId;

        if (!isNaN(climb_id)) {
            climb_id = parseInt(climb_id);
        }

        if (!isNaN(areaId)) {
            areaId = parseInt(areaId);
        }

        $scope.selected_ = {};
        $scope.items = [];
        $scope.details = true;
        // looping though all data and get particular product
        $scope.selectClimb = function(areas){
            areas.forEach(function(data) {
                if(data._id == climb_id){
                    $scope.selected_ = data;
                }
            });
        }
        // get all posts // try some function to get a single produt from server
        $scope.getPosts = function(){
            Climbs.getPosts()
            .success(function (data) {
                // data = feed.json file

                var climbs = [];
                data.areas.map(function(area) {
                    if (area._id === areaId) {
                        climbs = area.climbs;
                    }
                });
                $scope.selectClimb(climbs);
            })
            .error(function (error) {
                $scope.items = [];
            });
        }
        $scope.getPosts();


        $ionicModal.fromTemplateUrl('test-modal.html', {
            scope: $scope,
            animation: 'slide-in-up'
          }).then(function(modal) {
            $scope.modal = modal;
          });

          $scope.openModal = function() {
            $scope.modal.show();
          };
          $scope.closeModal = function() {
            $scope.modal.hide();
          };
          //Cleanup the modal when we're done with it!
          $scope.$on('$destroy', function() {
            $scope.modal.remove();
          });
          // Execute action on hide modal
          $scope.$on('modal.hidden', function() {
            // Execute action
          });
          // Execute action on remove modal
          $scope.$on('modal.removed', function() {
            // Execute action
          });

}])
Sign up to request clarification or add additional context in comments.

2 Comments

Thats it it was the } I had i the wrong spot that was mucking it up :) and the }]) now closes.
@user1155141 sounds great that your problem have been solved up vote it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.