Fix null pointer when scope.treeData hasn't been initialized yet

Moves `$scope.treeData` to just the directive and fix a null pointer when it hasn't been initialized.