I'm trying to figure out something with scope and link when a directive is initialized. I have a directive in a tree controller to display details at a branch point:
<typelists sub="branch.subBranches[0]"></typelists>
The (relevant parts of the) directive that handles that branch info are below:
listsApp.directive(
'typelists',
function($rootScope) {
return {
restrict: 'EA',
replace: true,
scope: {
branch : '=sub'
},
templateUrl: templateDir + '/typelists.html',
link: function (scope, element, attrs) {
console.log(scope,scope.branch); // DEBUG
// other stuff
// (including a working reload() and refresh() methods)
scope.subject = 'Type' + scope.branch.model.getFilter() + 'Lists';
// catch $rootScope.$broadcasts for this branch
$rootScope.$on( scope.subject+'Refresh', function() { scope.refresh(); ) } );
$rootScope.$on( scope.subject+'Reload', function() { scope.reload(); } );
}
};
Now, what is confusing the bajeezus out of me is that in the // DEBUG line, I can see .branch populated as expected in the output of the scope alone, but scope.branch shows as undefined. This means that when I try to set scope.subject down below, instead of getting a typeId back from the parent type, I'm getting 'undefined' so instead of getting a unique branch tag such as 'Type1Lists' I'm getting 'TypeundefinedLists', thus my $on watch functions aren't triggering properly.
Why am I unable to access scope.branch or why is it showing as undefined when I try? (especially when I can see it in the same console.log output as part of scope?)
Thanks in advance for any help.