or
$scope.performTreeSelect = function(selectedBB, updateMapper, breadCrumb, tabText) { var tree = $('#bb-tree').data('kendoTreeView'); // $scope.treeView // tabstrip start var tabstrip = $("#tabStrip").kendoTabStrip().data("kendoTabStrip"); $scope.bbDataSourceFactory.push({}); var bbDataSourceFactoryIndex = $scope.bbDataSourceFactory.length - 1; if (updateMapper) { bulletinBoardService.bbDataSourceMapper.push({"factoryIndex":bbDataSourceFactoryIndex, "selectedBBId":selectedBB,"breadCrumb":breadCrumb,"tabText":tabText }); } var bbDirectiveHTML = '<div style="padding-left: 60px;"><div><p>' + breadCrumb + '</p></div>' + '<display-basket grid-id="' + selectedBB +'" actions="bbActions" uids="uids" grid-options="bbOptions" grid-data-source-factory="bbDataSourceFactory[' + bbDataSourceFactoryIndex + ']" grid-data-source-options="bbDataSourceOptions">' + '</display-basket>'+ '</div>'; var bbDirective = angular.element(bbDirectiveHTML); tabstrip.append({text: tabText, content: ''}); angular.element(document.getElementById("tabStrip")).append(bbDirective); $compile(bbDirective)($scope);};$scope.$on('actionClick', function(e) { bulletinBoardService.selectedBBId = e.targetScope.gridId; $scope.uids = e.targetScope.uids; switch (arguments[1].ev) { case 'refresh': $scope.refresh(arguments[1].gridId); break; }});var populateGrid = function (selectedBB) { if ( selectedBB ) { for (var i=0; i< bulletinBoardService.bbDataSourceMapper.length; i++){ var it = bulletinBoardService.bbDataSourceMapper[i].selectedBBId; if (it == selectedBB){ $scope.bbDataSourceFactory[bulletinBoardService.bbDataSourceMapper[i].factoryIndex ] = function () { return CBPmWebAPI.BulletinBoardDocumentsDataSource( selectedBB, bulletinBoardService.bbDataSourceOptions ); }; break; } } }};link: function ( scope, element, attrs ) { element.prepend( bsktDirModule.formActionsDisplayHTML( scope.actions ) ); element.removeAttr("set_on_click"); $compile( element.contents() )( scope ); scope.$watch( 'gridDataSourceFactory', function ( gridDataSourceFactory, oldgridDataSourceFactory ) { if ( gridDataSourceFactory ) { // Set the grid's data source to the result of invoking the factory var grid = $( '#' + scope.gridId ).data( 'kendoGrid' ); // GRID IS UNDEFINED - WHY????? if (grid) { grid.setDataSource( gridDataSourceFactory() ); scope.uids = []; } } });},$scope.handleClick = function(msg) { $scope.$emit('actionClick', {ev: msg, gridId: $scope.gridId});};