AngularJS MTV Meetup: $provide Methods / Building Up with AngularJS (2012/11/13)

Angular · 16K views · 2012 · 1:58:33

Open on YouTube

Web developmentSoftware architecture & designtalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when explaining how AngularJS services, values, factories, providers and decorators differ, since few written sources covered them in 2013.

Recommended by 5 people across 5 different months, 2013 to 2013.

What it is

A recording of the AngularJS MTV meetup from November 2012. Google engineer Wesley Alvaro explains the different $provide methods (constant, value, service, factory, provider, decorator) and builds a simple client that reads Google Drive documents with OAuth, then Greg Weber of yap.tv covers design patterns for managing UI complexity.

What people said

Recommends Abraham P · 2013-01 · Stack Overflow · on “The view is not updated when the model updates in AngularJS”

[LINK] Your problem is twofold. 1) There was a syntax error in your jsfiddle, as DOMElements (such as the a returned by $(this) inside your clickhandler have no prevent default. You actually needed to pass an event. (Minor syntax issue). 2) By putting your variable definition within the controllers scope like so: function MyCtrl($scope){ $scope.foo = foo; } You ensure it gets run once per class instantiation. What you want is: function MyCtrl($scope){ $scope.someAngularClickHandler=function(){ $scope.foo = foo; } } And then on your link <a href="foo" id="bar" ng-click="someAngularClickHandler()"> For a more exhaustive codesample see the linked jsfiddle. A good overview of the theory can be f

Recommends Mark Rajcok · 2013-04 · Stack Overflow · on “angularjs value vs factory”

Set the value to an object, rather than a function: app.value('Data', {message:"I am data from a service"}); Plunker [LINK] See also provide.value() [LINK] , and this video about $provide [this video] (value, constant, service, factory, decorator, provider)

Recommends Miguel A. Carrasco · 2013-08 · Stack Overflow · on “Angularjs menu login logout loading”

Edit: After read the MarkRajcok comment I realized that this solution is coupling view from business logic layer, also it exposes the service variable to be changed outside the service logic, this is undesirable and error prone, so the $scope.$watch solution proposed by BoxerBucks it's probably better, sorry. You can use $scope.$watch as in the BoxerBucks answer, but I think that using watchers isn't proper for services, because usually you want to access services variables in differents controllers expecting that when you change that services variables, all the controllers that inject that service will be automatically updated, so I believe that this is a good way to solve your problem: In

Recommends shaunhusain · 2013-09 · Stack Overflow · on “How to deal with the URL in Angular?”

Yup here's the link to the description in the docs: [LINK] I watched a YouTube video on it that tipped me off initially and describes it fairly well [this video] the second talk wasn't as good

Recommends Iladarsda · 2013-11 · Stack Overflow · on “Where is a good place for me to declare / initialize $scope variables for my module?”

@Alan - to best of my understanding - service is initiated at the time of injection into a controller - and because services are singletons (one instance per app) should you use service in multiple places this single instance will be injected everywhere. For more in dept explanation watch this presentation by Wes Alvaro [this video] / slider here: [LINK]

Cites Kevin Beal · 2013-04 · Stack Overflow · on “What are "decorators" and how are they used?”

I'm curious what exactly decorators are in AngularJS. There isn't much information online for decorators save for a blurb in the AngularJS documentation [LINK] and a brief (albeit interesting) mention in a [this video] . As the Angular guys put it a decorator is: Decoration of service, allows the decorator to intercept the service instance creation. The returned instance may be the original instance, or a new instance which delegates to the original instance. I don't really know what that means , and I'm not sure why you would separate this logic from the service itself. For example if I wanted to return something different under different conditions I would just pass different arguments to the r

Cites Miguel A. Carrasco · 2013-08 · Stack Overflow · on “Angularjs menu login logout loading”

@MarkRajcok that's a good point, but then, why Wes Alvaro (the presenter of this video [this video] ) share that plunker as an example of how to use services for cross app/controller comunications as in this slide [LINK] Do you think that this is a bad practice?