Inside of your inner-directive's definition, you'd want to define a "scope" property.
angular.module(...).directive(..., ...function () {
var innerDirective = {
templateUrl : ...,
scope : {
loadingState : "="
},
link : function (scope, el, attrs, ctrl) {
scope.update = function () {
scope.loadingState.current += 1;
};
}
};
return innerDirective;
Inside of your outer-directive's template, when you call your inner-directive, you will add a "loading-state" attribute, and pass it a scope property from the outer-directive.
// in your outer-directive:
// $scope.loading.current = 0;
// $scope.$watch("loading.current", function (newVal) { $scope.updateView(newVal); });
The loadingState : "="
is a two-way data-binding between the inner scope and the outer scope.
The name you give it, inside of the inner-scope is the name of the property it expects in the HTML (almost like the HTML now has your constructor params).
There are cases where this will not go both ways, and will only go from parent to child.
Like if you try to make ngRepeat inner-directives.
Or if you use an ngIf to add/delete a child-directive.
I don't believe this is documented behaviour, but I do believe it's the current behaviour.