Is it possible to access single variable from rootScope in directives isolated scope?
I understand using scope: false will inherit all the properties from parent scope and scope: true will create a new scope by inheriting all the properties from parent scope.
Can we inherit just one property from parent scope so that the directive can be more modular and cleaner.
Here is case I'm referring to.
index.html
<body ng-app="app">
<header></header>
<div ui-view=""></div>
</body>
directive.html
<div>Parent prop is {{parentProp}}</div>
directive.js
app.directive('header', function ($rootScope) {
return {
templateUrl: "temp.html"
restrict: 'E',
scope: {
parentProp: "@"
},
controller: function () {
...
},
bindToController: true,
controllerAs: 'header'
};
});
app.js
app.run(function ($rootScope) {
$rootScope.$on('$stateChangeStart', function (event, next, nextParams) {
$rootScope.parentProp = false;
if(checkIfParentPropShouldBeTrue()) {
$rootScope.parentProp = true;
}
});
});
The parentProp property changes with state. Can I bind this property of rootScope to directive's isolated scope and manipulate directive's DOM respectively on every state change?