Last active
September 19, 2015 21:08
-
-
Save shotaK/0149196f20736b7210f1 to your computer and use it in GitHub Desktop.
AngularJS - styleguide
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
(function() { | |
'use strict'; | |
angular | |
.module('excursion', [ | |
'ngResource' | |
]); | |
})(); |
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
// some controller | |
$rootScope.isListing = false; | |
var page = '/listings'; | |
$rootScope.$on('$routeChangeSuccess', function (e, current, pre) { | |
var currentRoute = $location.path(); | |
(currentRoute == noFooterPage) ? $rootScope.isListing = true : $rootScope.isListing = false; | |
}); | |
// some html | |
<div ng-hide="isListing"> |
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
// Some controller | |
vm.parseTheDate = function(dateString) { | |
if (dateString) { | |
var properlyFormattedDate = dateString.split(" ").join("T"); | |
return new Date(properlyFormattedDate); | |
} else { | |
return null; | |
} | |
}; | |
// some html | |
<p>{{ vm.parseTheDate(vm.tour.created_at) | date:'short'}}</p> |
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
// ------------------ route-config.js ------------------ \\ | |
.when('/tours', { | |
templateUrl: 'scripts/partials/pages/tours.partial.html', | |
controller: 'TourController', | |
controllerAs: 'vm', | |
resolve: { | |
toursService: function(genericData) { | |
return genericData.getTours; | |
} | |
} | |
}) | |
// ------------------ tour.controller.js ------------------ \\ | |
(function() { | |
'use strict'; | |
angular | |
.module('excursion') | |
.controller('TourSingleController', TourSingleController); | |
TourSingleController.$inject = ['toursService']; | |
function TourSingleController(toursService) { | |
// vm is our capture variable | |
var vm = this; | |
vm.tour = toursService.getTours; | |
} | |
})(); |
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
(function () { | |
'use strict'; | |
angular | |
.module('excursion') | |
.config(config); | |
function config($routeProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: 'scripts/partials/home.partial.html', | |
controller: 'MainController', | |
controllerAs: 'vm' | |
}) | |
.when('/avengers', { | |
templateUrl: 'avengers.html', | |
controller: 'Avengers', | |
controllerAs: 'vm' | |
}); | |
} | |
})(); | |
// index.html file | |
<div ng-include="'scripts/partials/header.partial.html'"></div> | |
<div ng-view="" class="site-content" autoscroll="true"></div> | |
<div ng-include="'scripts/partials/footer.partial.html'"></div> |
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
(function() { | |
'use strict'; | |
angular | |
.module('excursion') | |
.controller('TourController', TourController); | |
function TourController(tours) { | |
// vm is our capture variable | |
var vm = this; | |
vm.tours = []; | |
// Fetches the time entries from the static JSON file | |
// and puts the results on the vm.timeentries array | |
tours.getTours().then(function(results) { | |
vm.tours = results; | |
console.log(vm.tours); | |
}, function(error) { // Check for errors | |
console.log(error); | |
}); | |
} | |
})(); |
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
(function() { | |
'use strict'; | |
angular | |
.module('excursion') | |
.factory('tours', tours); | |
function tours($resource) { | |
// ngResource call to our static data | |
var Tour = $resource('data/tours.json'); | |
function getTours() { | |
// $promise.then allows us to intercept the results | |
// which we will use later | |
return Tour.query().$promise.then(function(results) { | |
console.log(results); | |
return results; | |
}, function(error) { // Check for errors | |
console.log(error); | |
}); | |
} | |
return { | |
getTours: getTours | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment