Skip to content

Commit

Permalink
Changed $scope to this.
Browse files Browse the repository at this point in the history
  • Loading branch information
vzickner committed Oct 16, 2015
1 parent 0bd7613 commit 41208f3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
15 changes: 11 additions & 4 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ angular.module('geoTodoApp').config(['$routeProvider',
$routeProvider.
when('/map', {
templateUrl: 'partials/map.html',
controller: 'MapController'
controller: 'MapController',
controllerAs: 'ctrl'

}).
when('/list', {
templateUrl: 'partials/list.html',
controller: 'ListController'
controller: 'ListController',
controllerAs: 'ctrl'
}).
when('/detail/:locationId', {
templateUrl: 'partials/detail.html',
controller: 'DetailController'
controller: 'DetailController',
controllerAs: 'ctrl'

}).
when('/new', {
templateUrl: 'partials/new.html',
controller: 'NewController'
controller: 'NewController',
controllerAs: 'ctrl'

}).
otherwise({
redirectTo: '/map'
Expand Down
20 changes: 9 additions & 11 deletions js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ angular.module('geoTodoController').factory('Tasks', function ($resource) {
angular.module('geoTodoController').service('geocoder', function () {
this.geocode = function (address, outerCallback) {
var geocoder = new google.maps.Geocoder();

geocoder.geocode({'address': address}, function (results, status) {
$log(results);
if (status == google.maps.GeocoderStatus.OK) {
outerCallback({success: true, err: null, results: results});
} else {
Expand All @@ -26,8 +26,8 @@ angular.module('geoTodoController').service('geocoder', function () {
};
});

angular.module('geoTodoController').controller('MapController', ['$scope', 'Locations', function ($scope, Locations) {
var vm = $scope; // TODO: Should be this
angular.module('geoTodoController').controller('MapController', ['Locations', function (Locations) {
var vm = this;

vm.map = {center: {latitude: 51.163333, longitude: 10.447778}, zoom: 6};

Expand All @@ -40,22 +40,22 @@ angular.module('geoTodoController').controller('MapController', ['$scope', 'Loca
};
}]);

angular.module('geoTodoController').controller('ListController', ['$scope', 'Locations', function ($scope, Locations) {
var vm = $scope; // TODO: Should be this
angular.module('geoTodoController').controller('ListController', ['Locations', function (Locations) {
var vm = this;

Locations.query(function (data) {
vm.locations = data;
});
}]);

angular.module('geoTodoController').controller('DetailController', ['$scope', 'Locations', '$routeParams', function ($scope, Locations, $routeParams) {
var vm = $scope; // TODO: Should be this
angular.module('geoTodoController').controller('DetailController', ['Locations', '$routeParams', function (Locations, $routeParams) {
var vm = this;

vm.locationId = $routeParams.locationId;
}]);

angular.module('geoTodoController').controller('NewController', ['$scope', 'Locations', 'Tasks', 'geocoder', function ($scope, Locations, Tasks, geocoder) {
var vm = $scope; // TODO: Should be this
angular.module('geoTodoController').controller('NewController', ['Locations', 'Tasks', 'geocoder', function (Locations, Tasks, geocoder) {
var vm = this;

Tasks.query(function (data) {
vm.tasks = data;
Expand All @@ -72,8 +72,6 @@ angular.module('geoTodoController').controller('NewController', ['$scope', 'Loca

vm.inputName = '';
vm.inputLocation = '';

$log(results); //{success: true, err: undefined, results: {...} or {success:false, err: Error object, results: undefined}
});
};
}]);
2 changes: 1 addition & 1 deletion partials/detail.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{locationId}}
{{ctrl.locationId}}
2 changes: 1 addition & 1 deletion partials/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<th>{{ 'Location' | translate }}</th>
<th>&nbsp;</th>
</tr>
<tr ng-repeat="location in locations">
<tr ng-repeat="location in ctrl.locations">
<td>{{location.name}}</td>
<td>{{location.location}}</td>
<td><a href="#/detail/{{location.id}}" class="btn btn-primary"><i class="icon-show"></i> {{ 'Show' | translate }}</a></td>
Expand Down
6 changes: 3 additions & 3 deletions partials/map.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div>
<ui-gmap-google-map center='map.center' zoom='map.zoom'>
<ui-gmap-google-map center='ctrl.map.center' zoom='ctrl.map.zoom'>
<ui-gmap-marker
idKey="location.id"
coords='location'
options="location.options"
click="openDetails(location.id)"
data-ng-repeat="location in locations">
click="ctrl.openDetails(location.id)"
data-ng-repeat="location in ctrl.locations">
</ui-gmap-marker>
</ui-gmap-google-map>
</div>
10 changes: 5 additions & 5 deletions partials/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ <h1>{{ 'New Operation Request' | translate }}</h1>
<label for="inputName" class="col-sm-2 control-label">{{ 'Name' | translate }}:</label>

<div class="col-sm-8">
<input ng-model="inputName" id="inputName" class="form-control"/>
<input ng-model="ctrl.inputName" id="inputName" class="form-control"/>
</div>
</div>
<div class="form-group">
<label for="inputLocation" class="col-sm-2 control-label">{{ 'Location' | translate }}:</label>

<div class="col-sm-8">
<input ng-model="inputLocation" id="inputLocation" class="form-control"/>
<input ng-model="ctrl.inputLocation" id="inputLocation" class="form-control"/>
</div>
</div>
<div class="form-group">
<label for="inputProject" class="col-sm-2 control-label">{{ 'Project' | translate }}:</label>

<div class="col-sm-8">
<select ng-model="inputProject" id="inputProject" class="form-control">
<select ng-model="ctrl.inputProject" id="inputProject" class="form-control">

</select>
</div>
</div>
<div class="form-group">
<label for="inputTasks[]" class="col-sm-2 control-label">{{ 'Tasks' | translate }}:</label>

<div class="col-sm-8" ng-repeat="task in tasks">
<div class="col-sm-8" ng-repeat="task in ctrl.tasks">
<input type="checkbox" name="inputTasks[]" id="inputTasks[]" value="{{task.id}}"> {{task.name}}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<button type="button" ng-click="addNew()" class="btn btn-primary">{{ 'Save' | translate }}</button>
<button type="button" ng-click="ctrl.addNew()" class="btn btn-primary">{{ 'Save' | translate }}</button>
</div>
</div>
</form>

0 comments on commit 41208f3

Please sign in to comment.