Skip to content

Instantly share code, notes, and snippets.

@andresaraujo
Last active August 29, 2015 14:24
Show Gist options
  • Save andresaraujo/f491902ce97602a7efc2 to your computer and use it in GitHub Desktop.
Save andresaraujo/f491902ce97602a7efc2 to your computer and use it in GitHub Desktop.
Angular 1 without component directives
angular
.module('myApp', [])
.constant('profileId', 1)
.service('profileService', ProfileService)
.controller('profileController', ProfileController);
function ProfileService() {
this.mockData = {
1 : {'name': 'Daenerys Targaryen', 'quote': 'I am Daenerys Stormborn and I will take what is mine with fire and blood.'},
2 : {'name': 'Jon Snow', 'quote': 'Don’t call me Lord Snow.'},
3 : {'name': 'Hodor', 'quote': 'hodor'}
};
}
ProfileService.prototype.get = function(id) {
return this.mockData[id];
}
function ProfileController(profileId, profileService) {
this.data = profileService.get(profileId);
}
ProfileController.$inject = ['profileId', 'profileService'];
<body ng-app="myApp">
<div ng-controller="profileController as profile">
{{ profile.data.name }} - {{ profile.data.quote }}
</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment