Last active
August 29, 2015 14:24
-
-
Save andresaraujo/f491902ce97602a7efc2 to your computer and use it in GitHub Desktop.
Angular 1 without component directives
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('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']; |
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
<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