‘this’ vs $scope in AngularJS controllers

In the “Create Components” section of AngularJS’s homepage, there is this example: controller: function($scope, $element) { var panes = $scope.panes = []; $scope.select = function(pane) { angular.forEach(panes, function(pane) { pane.selected = false; }); pane.selected = true; } this.addPane = function(pane) { if (panes.length == 0) $scope.select(pane); panes.push(pane); } } Notice how the select method is … Read more

What are the nuances of scope prototypal / prototypical inheritance in AngularJS?

The API Reference Scope page says: A scope can inherit from a parent scope. The Developer Guide Scope page says: A scope (prototypically) inherits properties from its parent scope. So, does a child scope always prototypically inherit from its parent scope? Are there exceptions? When it does inherit, is it always normal JavaScript prototypal inheritance? … Read more

angular.service vs angular.factory

I have seen both angular.factory() and angular.service() used to declare services; however, I cannot find angular.service anywhere in official documentation. What is the difference between the two methods? Which should be used for what (assuming they do different things)? 9 s 9 angular.service(‘myService’, myServiceFunction); angular.factory(‘myFactory’, myFactoryFunction); I had trouble wrapping my head around this concept … Read more

What is the difference between ‘@’ and ‘=’ in directive scope in AngularJS?

I’ve read the AngularJS documentation on the topic carefully, and then fiddled around with a directive. Here’s the fiddle. And here are some relevant snippets: From the HTML: <pane bi-title=”title” title=”{{title}}”>{{text}}</pane> From the pane directive: scope: { biTitle: ‘=’, title: ‘@’, bar: ‘=’ }, There are several things I don’t get: Why do I have … Read more

What is the difference between angular-route and angular-ui-router?

I’m planning to use AngularJS in my big applications. So I’m in the process to find out the right modules to use. What is the difference between ngRoute (angular-route.js) and ui-router (angular-ui-router.js) modules? In many articles when ngRoute is used, route is configured with $routeProvider. However, when used with ui-router, route is configured with $stateProvider … Read more

How do I use $scope.$watch and $scope.$apply in AngularJS?

I don’t understand how to use $scope.$watch and $scope.$apply. The official documentation isn’t helpful. What I don’t understand specifically: Are they connected to the DOM? How can I update DOM changes to the model? What is the connection point between them? I tried this tutorial, but it takes the understanding of $watch and $apply for … Read more

How does data binding work in AngularJS?

How does data binding work in the AngularJS framework? I haven’t found technical details on their site. It’s more or less clear how it works when data is propagated from view to model. But how does AngularJS track changes of model properties without setters and getters? I found that there are JavaScript watchers that may … Read more

AngularJS: Service vs provider vs factory

What are the differences between a Service, Provider and Factory in AngularJS? 30 30 From the AngularJS mailing list I got an amazing thread that explains service vs factory vs provider and their injection usage. Compiling the answers: Services Syntax: module.service( ‘serviceName’, function ); Result: When declaring serviceName as an injectable argument you will be … Read more