The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

$provide.decorator

$provide.decorator

1:41
In this lesson Brett will show you how to use `$provide.decorator` to cleanly add functionality to AngularJS services and keep your concerns wonderfully separated.
Watch this lesson now
Avatar
egghead.io

In this lesson Brett will show you how to use $provide.decorator to cleanly add functionality to AngularJS services and keep your concerns wonderfully separated.

Avatar
Kevin

Can the following syntax be explained, I've never seen the following before this video involving a return statement:

return {
  // Code here 
}[pass_parameter]

Also, how would you decorate an array of objects within a service?

In reply to egghead.io
Avatar
Loic

Hi Kevin,

This is the same thing as this:

var tmp = {
   // list of properties here
};
return tmp[someVar];

In this tutorial, Brett use this technique to map a list of numerical error codes to something more user-friendly.

His code could be read like this:

var tmp = {
   15: 'Faulted'
};
return tmp[error]; // and error = 15
In reply to Kevin
Avatar
Kevin

Hey, Loic:

Thanks for the clarification; now I get it.

In reply to Loic
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?