Skip to content

Instantly share code, notes, and snippets.

@alatzl
Created May 12, 2015 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alatzl/ac2f29dedda7aa400c3a to your computer and use it in GitHub Desktop.
Save alatzl/ac2f29dedda7aa400c3a to your computer and use it in GitHub Desktop.
Use Angular.constant() and Angular.value()
// Instead of this:
angular.module('petStoreApp', [])
.controller('petStoreOneCtrl', function($scope) {
$scope.myCat = {
name: 'Grumpy',
type: 'cat'
};
$scope.myDog = {
name: 'Lassie',
type: 'dog'
};
})
.controller('petStoreTwoCtrl', function($scope) {
$scope.myOtherCat = {
name: 'Fluffy',
type: 'cat'
};
});
// Try this:
angular.module('petStoreApp', [])
.value('petTypes', {
CAT: 'cat',
DOG: 'dog'
})
.controller('petStoreOneCtrl', function($scope, petTypes) {
$scope.myCat = {
name: 'Grumpy',
type: petTypes.CAT
};
$scope.myDog = {
name: 'Lassie',
type: petTypes.DOG
};
})
.controller('petStoreTwoCtrl', function($scope, petTypes) {
$scope.myOtherCat = {
name: 'Fluffy',
type: petTypes.CAT
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment