Can an AngularJS controller inherit from another controller in the same module?

Within a module, a controller can inherit properties from an outside controller: var app = angular.module(‘angularjs-starter’, []); var ParentCtrl = function ($scope, $location) { }; app.controller(‘ChildCtrl’, function($scope, $injector) { $injector.invoke(ParentCtrl, this, {$scope: $scope}); }); Example via: Dead link: http://blog.omkarpatil.com/2013/02/controller-inheritance-in-angularjs.html Can also a controller inside a module inherit from a sibling? var app = angular.module(‘angularjs-starter’, []); … Read more

How do I use $rootScope in Angular to store variables?

How do I use $rootScope to store variables in a controller I want to later access in another controller? For example: angular.module(‘myApp’).controller(‘myCtrl’, function($scope) { var a = //something in the scope //put it in the root scope }); angular.module(‘myApp’).controller(‘myCtrl2’, function($scope) { var b = //get var a from root scope somehow //use var b }); … Read more

AngularJS: How can I pass variables between controllers?

I have two Angular controllers: function Ctrl1($scope) { $scope.prop1 = “First”; } function Ctrl2($scope) { $scope.prop2 = “Second”; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally } I can’t use Ctrl1 inside Ctrl2 because it is undefined. However if I try to pass it in like so… function Ctrl2($scope, … Read more