// 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);