AngularJS: open a new browser window, yet still retain scope and controller, and services

There is no [straightforward] way to make the new window belong to the same angular.js application, since the angular application is generally tied to the document, window, and events of the window where it was initialized either via an ng-app directive or by calling angular.bootstrap. However, you can create a new angular module and application … Read more

AngularJS : The correct way of binding to a service properties

Consider some pros and cons of the second approach: 0 {{lastUpdated}} instead of {{timerData.lastUpdated}}, which could just as easily be {{timer.lastUpdated}}, which I might argue is more readable (but let’s not argue… I’m giving this point a neutral rating so you decide for yourself) +1 It may be convenient that the controller acts as a … Read more

Update parent scope variable in AngularJS

You need to use an object (not a primitive) in the parent scope and then you will be able to update it directly from the child scope Parent: app.controller(‘ctrlParent’,function($scope){ $scope.parentprimitive = “someprimitive”; $scope.parentobj = {}; $scope.parentobj.parentproperty = “someproperty”; }); Child: app.controller(‘ctrlChild’,function($scope){ $scope.parentprimitive = “this will NOT modify the parent”; //new child scope variable $scope.parentobj.parentproperty = … Read more

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

Yes, it can but you have to use the $controller service to instantiate the controller instead:- var app = angular.module(‘angularjs-starter’, []); app.controller(‘ParentCtrl’, function($scope) { // I’m the sibling, but want to act as parent }); app.controller(‘ChildCtrl’, function($scope, $controller) { $controller(‘ParentCtrl’, {$scope: $scope}); //This works });

How do I inject a controller into another controller in AngularJS

If your intention is to get hold of already instantiated controller of another component and that if you are following component/directive based approach you can always require a controller (instance of a component) from a another component that follows a certain hierarchy. For example: //some container component that provides a wizard and transcludes the page … Read more

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

Variables set at the root-scope are available to the controller scope via prototypical inheritance. Here is a modified version of @Nitish’s demo that shows the relationship a bit clearer: http://jsfiddle.net/TmPk5/6/ Notice that the rootScope’s variable is set when the module initializes, and then each of the inherited scope’s get their own copy which can be … Read more

Angularjs Uncaught Error: [$injector:modulerr] when migrating to V1.3

After AngularJS version 1.3 global controller function declaration is disabled You need to first create an AngularJS module & then attach all the components to that specific module. CODE function Ctrl($scope) { $scope.age = 24; } angular.module(‘app’, []) .controller(‘Ctrl’, [‘$scope’, Ctrl]); Specifically for your case, there is some issue with AngularJS 1.3.14 (downgrade it to … Read more

AngularJS: How can I pass variables between controllers?

One way to share variables across multiple controllers is to create a service and inject it in any controller where you want to use it. Simple service example: angular.module(‘myApp’, []) .service(‘sharedProperties’, function () { var property = ‘First’; return { getProperty: function () { return property; }, setProperty: function(value) { property = value; } }; … Read more