From 96dc2929ee9a6cfe643cb2b7edfd9257606f7dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Prokopowicz?= Date: Wed, 17 Jun 2015 11:40:57 +0200 Subject: [PATCH 1/2] fix($mdUtil): make "initOptionalProperties" compatible with angular >= 1.4.1 starting form angular 1.4.1 attrs defined in directive isolated scope are always present in $attrs Closes #3315 --- src/core/util/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/util/util.js b/src/core/util/util.js index cc7072abfbe..1407ae29f6c 100644 --- a/src/core/util/util.js +++ b/src/core/util/util.js @@ -334,15 +334,16 @@ angular.module('material.core') }, /** - * Give optional properties with no value a boolean true by default + * Give optional properties with no value a boolean true if attr provided or false otherwise */ initOptionalProperties: function (scope, attr, defaults ) { defaults = defaults || { }; angular.forEach(scope.$$isolateBindings, function (binding, key) { + var normalizedAttrName = attr.$normalize(binding.attrName); if (binding.optional && angular.isUndefined(scope[key])) { - var hasKey = attr.hasOwnProperty(attr.$normalize(binding.attrName)); + var attrIsDefined = normalizedAttrName in attr && !angular.isUndefined(attr[normalizedAttrName]); - scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : hasKey; + scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined; } }); } From cd58efd5c6bcb1c133b427f3a019c3e3fa55705d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Prokopowicz?= Date: Wed, 17 Jun 2015 14:47:52 +0200 Subject: [PATCH 2/2] refactor($mdUtil): simplify "initOptionalProperties" logic --- src/core/util/util.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/util/util.js b/src/core/util/util.js index 1407ae29f6c..bbda5d38cea 100644 --- a/src/core/util/util.js +++ b/src/core/util/util.js @@ -339,10 +339,8 @@ angular.module('material.core') initOptionalProperties: function (scope, attr, defaults ) { defaults = defaults || { }; angular.forEach(scope.$$isolateBindings, function (binding, key) { - var normalizedAttrName = attr.$normalize(binding.attrName); if (binding.optional && angular.isUndefined(scope[key])) { - var attrIsDefined = normalizedAttrName in attr && !angular.isUndefined(attr[normalizedAttrName]); - + var attrIsDefined = angular.isDefined(attr[binding.attrName]); scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined; } });