Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 531a8de

Browse files
Puigcerbercaitp
authored andcommitted
fix($observe): check if the attribute is undefined
Check if the attribute is undefined before manually applying the function because if not an undefined property is added to the scope of the form controller when the input control does not have a name. Closes #9707 Closes #9720
1 parent d488a89 commit 531a8de

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10721072

10731073
listeners.push(fn);
10741074
$rootScope.$evalAsync(function() {
1075-
if (!listeners.$$inter) {
1075+
if (!listeners.$$inter && attrs.hasOwnProperty(key)) {
10761076
// no one registered attribute interpolation function, so lets call it manually
10771077
fn(attrs[key]);
10781078
}

test/ng/directive/inputSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,24 @@ describe('input', function() {
13311331
expect(scope.name).toEqual('adam');
13321332
});
13331333

1334+
1335+
it('should not add the property to the scope if name is unspecified', function() {
1336+
inputElm = jqLite('<input type="text" ng-model="name">');
1337+
formElm = jqLite('<form name="form"></form>');
1338+
formElm.append(inputElm);
1339+
$compile(formElm)(scope);
1340+
1341+
spyOn(scope.form, '$addControl').andCallThrough();
1342+
spyOn(scope.form, '$$renameControl').andCallThrough();
1343+
1344+
scope.$digest();
1345+
1346+
expect(scope.form['undefined']).toBeUndefined();
1347+
expect(scope.form.$addControl).not.toHaveBeenCalled();
1348+
expect(scope.form.$$renameControl).not.toHaveBeenCalled();
1349+
});
1350+
1351+
13341352
describe('compositionevents', function() {
13351353
it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function($sniffer) {
13361354
$sniffer.android = false;

0 commit comments

Comments
 (0)