Reputation: 124
Thanks for checking out my question, I'm relatively new to AngularJS so any advice would be great.
I'm trying to create a factory/service/provider, but I keep getting errors and can't get it to work right.
here is my Provider:
app.provider('createEventProvider', function() {
this.event = {
name: '',
when: '',
where: '',
description: '',
image: ''
};
this.$get = function(){
var event = this.event;
return
{
getEvent: function()
{
return event
}
}
}
this.setEventData = function(eventProp, data)
{
this.event[eventProp] = data;
};
});
and here is my controller:
app.controller('createEventController', function($scope, createEventProvider){
$scope.event = createEventProvider.getEvent();
});
When I run my code I get this error message: Uncaught SyntaxError: Unexpected token ) referring to this line of my provider: this.$get = function(){
I've been jumping around looking at different tutorials and haven't been able to find the answer. Any help, advice, or tips would be greatly appreciated!
Let me know if you need anymore of my code to solve the problem.
Upvotes: 0
Views: 100
Reputation: 25159
Actually it's this line part:
return
{
getEvent: function()
{
return event
}
}
You're a little overeager with your line returns. Move the object definition start to the return line and you'll be ok:
return {
getEvent: function() {
return event
}
}
Upvotes: 5