From 9d8eac24904fcafc35a1cd27b7971fe2f0eaa640 Mon Sep 17 00:00:00 2001 From: Pablo Villoslada Puigcerber Date: Tue, 21 Oct 2014 13:57:48 +0200 Subject: [PATCH] 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 --- src/ng/compile.js | 2 +- test/ng/directive/inputSpec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index b882b826388e..81aca9da7b78 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1073,7 +1073,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { listeners.push(fn); $rootScope.$evalAsync(function() { - if (!listeners.$$inter) { + if (!listeners.$$inter && attrs.hasOwnProperty(key)) { // no one registered attribute interpolation function, so lets call it manually fn(attrs[key]); } diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 0366aa786aaa..0d425d5367bd 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -1331,6 +1331,11 @@ describe('input', function() { expect(scope.name).toEqual('adam'); }); + it('should not add the property to the scope if name is undefined', function() { + compileInput(''); + expect(scope.form['undefined']).toBeUndefined(); + }); + describe('compositionevents', function() { it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function($sniffer) { $sniffer.android = false;