Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-05-13-15-51-23
[civicrm-core.git] / ang / crmUi.js
index 6e102ca37170f75c4eea35aee1ccc5c87f612a7b..cd61238787bcc711f0d24e3f9acb906915047aa1 100644 (file)
           // In cases where UI initiates update, there may be an extra
           // call to refreshUI, but it doesn't create a cycle.
 
-          ngModel.$render = function () {
-            $timeout(function () {
-              // ex: msg_template_id adds new item then selects it; use $timeout to ensure that
-              // new item is added before selection is made
-              element.select2('val', ngModel.$viewValue);
-            });
-          };
+          if (ngModel) {
+            ngModel.$render = function () {
+              $timeout(function () {
+                // ex: msg_template_id adds new item then selects it; use $timeout to ensure that
+                // new item is added before selection is made
+                element.select2('val', ngModel.$viewValue);
+              });
+            };
+          }
           function refreshModel() {
             var oldValue = ngModel.$viewValue, newValue = element.select2('val');
             if (oldValue != newValue) {
           function init() {
             // TODO watch select2-options
             element.select2(scope.crmUiSelect || {});
-            element.on('change', refreshModel);
-            $timeout(ngModel.$render);
+            if (ngModel) {
+              element.on('change', refreshModel);
+              $timeout(ngModel.$render);
+            }
           }
 
           init();
           }
 
           function init() {
-            // TODO watch options
             // TODO can we infer "entity" from model?
             element.crmEntityRef(scope.crmEntityref || {});
             element.on('change', refreshModel);