Angular RootScope with Scope relation

How to use rootscope

by Rajdeep Chandra

HTML

<div ng-controller="parentController">
  Hi My Name is {{name}}
  <div ng-controller="childController">
    My salary is {{salary | currency}} and my Dept is {{Dept}}
    <h1>
    Employee Paycheck
    </h1>
    <div ng-controller="emppaycheck">
      Taxes is {{getTaxes() | currency}} Net is {{NetInc() | currency}}
    </div>
  </div>
</div>

JavaScript

var app = angular.module('newRoot', []) //initialize rootscope
.run(['$rootScope', function($rootScope) {
  $rootScope.TaxPercent = 35;
}]);
app.controller('parentController', ['$scope', function($scope) {
  $scope.name = "Rajdeep";
}]);
app.controller('childController', ['$scope', function($scope) {
  $scope.salary = 3400;
  $scope.Dept = "Sales";
}]);
//Calling rootscope dependency injection from run method
app.controller('emppaycheck', ['$scope', '$rootScope', function($scope, $rootScope) {
//define getTaxes function
  $scope.getTaxes = function() {
    return $scope.salary * $rootScope.TaxPercent / 100;
  };
  $scope.NetInc = function() {
    return $scope.salary - $scope.getTaxes();
  };
}]);