|
134 | 134 |
|
135 | 135 | function modelAccessor(scope, element) { |
136 | 136 | var expr = element.attr('name'); |
137 | | - if (!expr) throw "Required field 'name' not found."; |
138 | | - return { |
139 | | - get: function() { |
140 | | - return scope.$eval(expr); |
141 | | - }, |
142 | | - set: function(value) { |
143 | | - if (value !== _undefined) { |
144 | | - return scope.$tryEval(expr + '=' + toJson(value), element); |
| 137 | + if (expr) { |
| 138 | + return { |
| 139 | + get: function() { |
| 140 | + return scope.$eval(expr); |
| 141 | + }, |
| 142 | + set: function(value) { |
| 143 | + if (value !== _undefined) { |
| 144 | + return scope.$tryEval(expr + '=' + toJson(value), element); |
| 145 | + } |
145 | 146 | } |
146 | | - } |
147 | | - }; |
| 147 | + }; |
| 148 | + } |
148 | 149 | } |
149 | 150 |
|
150 | 151 | function modelFormattedAccessor(scope, element) { |
151 | 152 | var accessor = modelAccessor(scope, element), |
152 | 153 | formatterName = element.attr('ng:format') || NOOP, |
153 | 154 | formatter = angularFormatter(formatterName); |
154 | 155 | if (!formatter) throw "Formatter named '" + formatterName + "' not found."; |
155 | | - return { |
156 | | - get: function() { |
157 | | - return formatter.format(accessor.get()); |
158 | | - }, |
159 | | - set: function(value) { |
160 | | - return accessor.set(formatter.parse(value)); |
161 | | - } |
162 | | - }; |
| 156 | + if (accessor) { |
| 157 | + return { |
| 158 | + get: function() { |
| 159 | + return formatter.format(accessor.get()); |
| 160 | + }, |
| 161 | + set: function(value) { |
| 162 | + return accessor.set(formatter.parse(value)); |
| 163 | + } |
| 164 | + }; |
| 165 | + } |
163 | 166 | } |
164 | 167 |
|
165 | 168 | function compileValidator(expr) { |
@@ -458,25 +461,27 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn, dirtyChecking) |
458 | 461 | view = viewAccessor(scope, element), |
459 | 462 | action = element.attr('ng:change') || '', |
460 | 463 | lastValue; |
461 | | - initFn.call(scope, model, view, element); |
462 | | - this.$eval(element.attr('ng:init')||''); |
463 | | - // Don't register a handler if we are a button (noopAccessor) and there is no action |
464 | | - if (action || modelAccessor !== noopAccessor) { |
465 | | - element.bind(events, function (){ |
466 | | - var value = view.get(); |
467 | | - if (!dirtyChecking || value != lastValue) { |
468 | | - model.set(value); |
469 | | - lastValue = model.get(); |
470 | | - scope.$tryEval(action, element); |
471 | | - scope.$root.$eval(); |
| 464 | + if (model) { |
| 465 | + initFn.call(scope, model, view, element); |
| 466 | + this.$eval(element.attr('ng:init')||''); |
| 467 | + // Don't register a handler if we are a button (noopAccessor) and there is no action |
| 468 | + if (action || modelAccessor !== noopAccessor) { |
| 469 | + element.bind(events, function (){ |
| 470 | + var value = view.get(); |
| 471 | + if (!dirtyChecking || value != lastValue) { |
| 472 | + model.set(value); |
| 473 | + lastValue = model.get(); |
| 474 | + scope.$tryEval(action, element); |
| 475 | + scope.$root.$eval(); |
| 476 | + } |
| 477 | + }); |
| 478 | + } |
| 479 | + scope.$watch(model.get, function(value){ |
| 480 | + if (lastValue !== value) { |
| 481 | + view.set(lastValue = value); |
472 | 482 | } |
473 | 483 | }); |
474 | 484 | } |
475 | | - scope.$watch(model.get, function(value){ |
476 | | - if (lastValue !== value) { |
477 | | - view.set(lastValue = value); |
478 | | - } |
479 | | - }); |
480 | 485 | }; |
481 | 486 | } |
482 | 487 |
|
|
0 commit comments