I am primirarily from Java with some exp. in javascript and starting with 
angularjs 

var mainApp = angular.module('MyApp', [ 'ngRoute', 'ngCordova' ]);

mainApp.controller("SimpleController", function SimpleController($scope,
        $cordovaGeolocation, $cordovaDevice, $cordovaVibration, cordovaSvc) 
{

    $scope.customers = [ {
        name : 'Name1',
        city : 'City1'
    }, {
        name : 'Name2',
        city : 'City2'
    }, {
        name : 'Name3',
        city : 'City3'
    } ];

    if(typeof deviceready != "undefined")
    {
        var posOptions = {
            timeout : 10000,
            enableHighAccuracy : true
        };
        $cordovaGeolocation.getCurrentPosition(posOptions).then(
            function(position) 
            {
                var latitude = position.coords.latitude
                var longitude = position.coords.longitude
                $scope.latitude = latitude;
                $scope.longitude = longitude;
            },
            function(err) 
            {
                $scope.longitude = "Error" + err.code + ", me: "
                        + err.message;
            }
        );
    }
    
    document.addEventListener("deviceready", function() {
        var posOptions = {
        timeout : 10000,
        enableHighAccuracy : true
        };
        $cordovaGeolocation.getCurrentPosition(posOptions).then(
                function(position) 
                {
                    var latitude = position.coords.latitude
                    var longitude = position.coords.longitude
                    $scope.latitude = latitude;
                    $scope.longitude = longitude;
                },
                function(err) 
                {
                    $scope.longitude = "Error" + err.code + ", me: "
                            + err.message;
                }
        );
        }, false);
    });

mainApp.config(function($routeProvider) {
    $routeProvider.when('/', {
        controller : 'SimpleController',
        templateUrl : 'View1.html'
    }).when('/partial2', {
        controller : 'SimpleController',
        templateUrl : 'View2.html'
    }).otherwise({
        redirectTo : '/'
    });
});

Same code I am writing exactly two times. Can't I put this into a separate 
one and call from both places...?

When I am trying this, regular variables like $scope etc are not being 
resolved. I tried passing these and then using in a custom function but 
didn't work. Please guide what's the best way

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to