Merge pull request #23902 from civicrm/5.51
[civicrm-core.git] / ang / crmUi.js
index c4559514175025e194d73f7d3a8d79767b0c751a..11eb5e28ef31ba75f49c5f118170d48fadeefa29 100644 (file)
             }
           }
 
-          init();
+          // If using ngOptions, wait for them to load
+          if (attrs.ngOptions) {
+            $timeout(init);
+          } else {
+            init();
+          }
         }
       };
     })
         templateUrl: '~/crmUi/tabset.html',
         transclude: true,
         controllerAs: 'crmUiTabSetCtrl',
-        controller: function($scope, $parse) {
-          var tabs = $scope.tabs = []; // array<$scope>
+        controller: function($scope, $element, $timeout) {
+          var init;
+          $scope.tabs = [];
           this.add = function(tab) {
             if (!tab.id) throw "Tab is missing 'id'";
-            tabs.push(tab);
+            $scope.tabs.push(tab);
+
+            // Init jQuery.tabs() once all tabs have been added
+            if (init) {
+              $timeout.cancel(init);
+            }
+            init = $timeout(function() {
+              $element.find('.crm-tabset').tabs($scope.tabSetOptions);
+            });
           };
-        },
-        link: function (scope, element, attrs) {}
+        }
       };
     })