Below is my html and javascript
<div ng-app="myApp" ng-controller="myCtrl">
{{firstname}}
<sample-directive></sample-directive>
</div>
JS
var app = angular.module("myApp", []);
app.run(function($rootScope){
$rootScope.firstname = "Root scope value"
});
app.controller("myCtrl", function($scope) {
});
app.directive("sampleDirective",function(){
return{
template:"<div>{{firstname}}</div>",
controller:['$scope',sampleDirectiveScope]
};
});
function sampleDirectiveScope($scope){
$scope.firstname = "scope value";
};
I am expecting "Root scope value" to be shown in the expression and "Scope value" to be displayed inside the directive tag
Why are both of them displaying Scope value?
Shouldn't the expression {{firstname}}
get value from rootscope as I have changed the firstname only inside the directive's controller?