Skip to content

Instantly share code, notes, and snippets.

@sscovil
Last active January 27, 2016 12:27
Show Gist options
  • Save sscovil/c64879bd7b527dd0dfd3 to your computer and use it in GitHub Desktop.
Save sscovil/c64879bd7b527dd0dfd3 to your computer and use it in GitHub Desktop.
angular.module('behaviour', [])
.factory('behaviours', behavioursFactory)
;
behavioursFactory.$inject = ['$http'];
function behavioursFactory($http) {
var behaviours;
$http.get('data.json').then(function(res) {
behaviours = res.data;
}, function(err) {
/* hanlde http error */
});
return {
get: function(name) {
if (!behaviours) {
/* http request failed or is still in progress */
} else if (behaviours[name]) {
/* behaviour exists, do something */
} else {
/* no behaviour with given name */
}
}
};
}
@MohamedFaesal
Copy link

it tells me that behaviours[name] is not an object and it's undefined ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment