Created
July 24, 2015 03:13
-
-
Save Ntropish/c33b77e11c3cdc0065fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout | |
block scripts | |
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js") | |
script(src="javascripts/index.js") | |
block content | |
div(ng-app="nightlife" ng-controller="NightlifeCtrl as nl") | |
button(class="btn" ng-click="findBars()") | |
| Find local bars | |
div(ng-repeat="bar in bars") | |
h4.ng-cloak {{ bar.name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('nightlife', []) | |
.controller('NightlifeCtrl', ['$scope', function ($scope) { | |
$scope.bars = [{name: 'ayo'}]; | |
$scope.user = {}; | |
$scope.latLong = ''; | |
function getLocation() { | |
navigator.geolocation.getCurrentPosition(function (position) { | |
var latitude = position.coords.latitude; | |
var longitude = position.coords.longitude; | |
$scope.latLong = latitude + ',' + longitude; | |
}); | |
} | |
getLocation(); | |
$scope.findBars = function findBars() { | |
if ($scope.latLong) { | |
$.ajax('/city', | |
{ | |
type: 'GET', | |
data: { | |
location: $scope.latLong | |
}, | |
success: function(res){ | |
$scope.$apply(function(){ | |
$scope.bars = res; | |
}) | |
} | |
} | |
); | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment