Var app = isn't working locally


#1

Hi, building this locally, however, the app can't load when i try to write the module like in the tutorial, i.e.:

var app = angular.module...

and then reference it in the MainController.js file etc like this:

app.controller...

which forces me to create a huge, chained app.js file with controller, config, and now factory all in one monstrous file. it worked fine for Nearme1, but now that i need the service, i run into an issue, as the service should be loaded at the end of the DOM, and the app.js is loaded at the beginning, which means that while in my app.js the service can't load cause its not ready.

why can't i turn my app into a variable, any ideas?

angular.module('NearMeApp',['leaflet-directive','ngRoute']).
config(['$routeProvider',function($routeProvider){
	$routeProvider.
		when('/',{
			templateUrl: 'js/views/main.html',
	  		controller: 'MainController'    
		}).
		when('/about',{
			templateUrl: 'js/views/about.html',
	  		controller: 'AboutController'
		}).
		otherwise({
			redirectTo: '/'
		});
}]).
controller("MainController", ['$scope','places', function($scope,places){
	$scope.mapCenter = {
		lat: 40.741934,
      	lng: -74.004897,
      	zoom: 17
	};
	places.success(function(data){
		$scope.geodata = data;
		$scope.mapMarkers = geodataToMarkers($scope.geodata);
	});
}]).
factory('places',['$http', function($http){
	return
	$http.jasonp('https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gsradius=5000&gscoord=40.741934%7C-74.004897&gslimit=30&format=json&callback=JSON_CALLBACK').
		success(function(data){
			return data;
		}).
		error(function(error){
			return error;
		});
}]);

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.