HTML
<div class="block-area" id="basic" ng-controller="DocumentEditorController">
<docs-hierarchy table-of-contents="document.toc" document-id="123123123">
</docs-hierarchy>
</div>
Directive
.directive('docsHierarchy', [function() {
return {
restrict: 'E',
scope: {
tableOfContents: '=',
documentId: '@',
},
template: '' +
'<docs-hierarchy-tree-render tree="tree"></docs-hierarchy-tree-render>' +
'',
link: function($scope, elem, attrs) {
$scope.meta = {};
$scope.tree = {};
function parseTree() {
console.log("TOC", "$scope:", $scope);
console.log("TOC", "$scope.tableOfContents:", $scope.tableOfContents);
console.log("TOC", "$scope.tree:", $scope.tree);
console.log("TOC", "$scope.documentId:", $scope.documentId);
}
parseTree();
}
Simply, I don't get how the value can be there in the $scope
value output, and immediately be undefined
the very next line. Why am I unable to get this value as already evaluated?
yet I can grab the string binding just fine.
EDIT 01
I managed to figure out a first pass way of doing this, like this:
.directive('docsHierarchy', [function() {
return {
restrict: 'E',
scope: {
tableOfContents: '=',
documentId: '@',
},
template: '' +
'<docs-hierarchy-tree-render tree="tree"></docs-hierarchy-tree-render>' +
'',
link: function($scope, elem, attrs) {
$scope.meta = {};
$scope.tree = {};
function parseTree() {
console.log($scope.toc);
}
$scope.$watch('tableOfContents', function(newVal, oldVal) {
if(newVal !== oldVal) {
$scope.toc = newVal;
parseTree();
}
});
}
};
}])
I still don't get why I have to do this though, if tableOfContents
is supposedly data bound