angular rootscope
by vignesh subramanian
HTML
<script src="https://code.angularjs.org/1.4.8/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
{{firstname}}
<sample-directive></sample-directive>
</div>
JavaScript
var app = angular.module("myApp", []);
app.run(function($rootScope){
$rootScope.firstname = "Root scope"
});
app.controller("myCtrl", function($scope) {
$scope.lastName= "Doe";
});
app.directive("sampleDirective",function(){
return{
template:"<div>{{firstname}}</div>",
controller:['$scope',sampleDirectiveScope]
};
});
function sampleDirectiveScope($scope){
$scope.firstname = "scope";
};