Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Con you please tell how to call the view page after all the operations done in the controller. Currently i am facing issues as in javascript, i am assigning a variable which will come after calling a service from controller and the data from services will come after some time.

share|improve this question
1  
Could you give us more information.. for example code?? – yuro Jun 19 at 15:04
    
Like say i want to pass my current lat long to get map information. – Abhranil Majumder Jun 20 at 5:16

From this controller i want to fetch map information from my lat long after certain interval of time but in the view page i am getting the map information but after fraction of seconds so i am facing problem in the google map as the variable which i defined in view page is undefined for fraction of second. I tried by setting the value in a hidden variable and getting the data but the variable defined in script is undefined.

frontApp.controller('mapController', function ($scope, $rootScope, services, $location, $window, $interval) {

    is_login(1);
    update();

    function update() {

        if (navigator.geolocation) {


            $window.navigator.geolocation.getCurrentPosition(function (position) {
                $scope.$apply(function () {

                    var latitude = position.coords.latitude;
                    var longitude = position.coords.longitude;


                    services.getMapData(latitude, longitude).then(function (data) {

                        $scope.mapdata = data.data;

                });
            });

        }
        else
        {
            window.location.href = site_url + "#/dashboard";
        }
    }

    $interval(update, 1000);
});
share|improve this answer
    
you should edit your original question with this new information – spanndemic Jun 20 at 6:14

I'm no expert so i'm sure someone with more experience will chime in. I'm pretty sure you need to initialize the module correctly. Your example doesn't appear have any dependencies defined (i.e. $scope, $location...etc).

//you also need the app as well inorder to attach the controller to.

var frontApp = angular.module('mappingModule', []);

frontApp.controller('mapController',['$scope', '$rootscope','$location','$window', '$interval', function ($scope, $rootScope, services, $location, $window, $interval) {

// do things with your data here.
// i'm going to out on a limb and say you probably need to make sure you have a popup that 
// that prompts to user to share their location or navigator wont give it to you
}]);

Also if you want the module to run you need to link onto the page. More of your code and setup is needed to provide a better answer.

You also need to define Services. uh, I believe it's called a Factory that takes care of that which needs to be referenced in a dependency in the controller dependencies array. Seeing your services code would help.

Overall it sounds like you aren't passing the location data to the controller.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.