[ Launch: Three Circles Setup ] fa065de546d6df931b9c by alatzl[ Launch: Three Circles Setup ] c6a6d74703906368d8df by alatzl[ Launch: Three Circles Answer ] 6258892 by lewis500[ Launch: Three Circles Answer ] 5565405 by lewis500
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('myModule') | |
.service('addresses', ['addressService', '$q', function(addressService, $q) { | |
this.prefix = 'My Address: '; | |
this.printAddress = function() { | |
var deferred = $q.defer(), | |
self = this; | |
addressService.getFullAddress(function(addr) { | |
deferred.resolve(self.prefix + addr); |
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('myModule') | |
.service('addresses', ['addressService', '$q', Addresses]); | |
class Addresses { | |
constructor(addressService, $q) { | |
this.$q = $q; | |
this.addressService = addressService; | |
this.prefix = "My Address: " | |
} | |
printAddress() { |
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('myModule') | |
.directive('roar', function() { | |
return { | |
restrict: 'E', | |
scope: { | |
dinoType: '@' | |
}, | |
template: '<p>I am a {{ getType }}, hear me ROAR!</p>', | |
link: function(scope) { | |
scope.getType = function() { |
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('myModule') | |
.directive('roar', function() { | |
return { | |
restrict: 'E', | |
scope: {}, | |
controller: roarCtrl, | |
controllerAs: dinoRoar, | |
bindToController: { | |
dinoType: '@' | |
} |
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
// Instead of this: | |
angular.module('app', []) | |
.controller('MyCtrl', function($scope) { | |
// What is moment? How do I know this exists and is the right object? | |
$scope.startTime = moment(); | |
$scope.endTime - moment().add(1, 'h'); | |
}); | |
// Try this: | |
angular.module('app', []) |
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
// Instead of using $.ajax for an API call... | |
angular.module('app', []) | |
.factory('addressBook', function() { | |
var data = null; | |
return { | |
getAddresses: function() { | |
$.ajax({ | |
url: '/path/to/data', | |
dataType: 'json', |
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
// Base service | |
angular.module('petStoreApp', []) | |
.service('petService', function($http) { | |
var petSvc = function(_endpoint_) { | |
var endpoint = _endpoint_ + '/'; | |
return { | |
getList: getList, | |
getInfo: getInfo | |
}; |
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
// Instead of this: | |
angular.module('petStoreApp', []) | |
.controller('petStoreOneCtrl', function($scope) { | |
$scope.myCat = { | |
name: 'Grumpy', | |
type: 'cat' | |
}; | |
$scope.myDog = { | |
name: 'Lassie', | |
type: 'dog' |
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
// An example showing two services that are nearly identical | |
angular.module('petStoreApp', []) | |
.service('catService', function($http) { | |
var svc = { | |
getList: function() { // get a list of all cats | |
$http({ method: 'GET', url: 'cats/all' }) | |
.then(successFn, errorFn); | |
}, | |
getInfo: function(catId) { // get info about a specific cat | |
$http({ method: 'GET', url: 'cats/' + catId }) |
OlderNewer