diff --git a/src/components/icon/iconService.js b/src/components/icon/iconService.js
index b631d4cc3b6..0c5b1dcb150 100644
--- a/src/components/icon/iconService.js
+++ b/src/components/icon/iconService.js
@@ -394,10 +394,8 @@
if ( urlRegex.test(id) ) return loadByURL(id).then( cacheIcon(id) );
if ( id.indexOf(':') == -1 ) id = '$default:' + id;
- return loadByID(id)
- .catch(loadFromIconSet)
- .catch(announceIdNotFound)
- .catch(announceNotFound)
+ var load = config[id] ? loadByID : loadFromIconSet;
+ return load(id)
.then( cacheIcon(id) );
}
@@ -435,9 +433,8 @@
*
*/
function loadByID(id) {
- var iconConfig = config[id];
-
- return !iconConfig ? $q.reject(id) : loadByURL(iconConfig.url).then(function(icon) {
+ var iconConfig = config[id];
+ return loadByURL(iconConfig.url).then(function(icon) {
return new Icon(icon, iconConfig);
});
}
@@ -450,12 +447,19 @@
var setName = id.substring(0, id.lastIndexOf(':')) || '$default';
var iconSetConfig = config[setName];
- return !iconSetConfig ? $q.reject(id) : loadByURL(iconSetConfig.url).then(extractFromSet);
+ return !iconSetConfig ? announceIdNotFound(id) : loadByURL(iconSetConfig.url).then(extractFromSet);
function extractFromSet(set) {
var iconName = id.slice(id.lastIndexOf(':') + 1);
var icon = set.querySelector('#' + iconName);
- return !icon ? $q.reject(id) : new Icon(icon, iconSetConfig);
+ return !icon ? announceIdNotFound(id) : new Icon(icon, iconSetConfig);
+ }
+
+ function announceIdNotFound(id) {
+ var msg = 'icon ' + id + ' not found';
+ $log.warn(msg);
+
+ return $q.reject(msg || id);
}
}
@@ -468,22 +472,7 @@
.get(url, { cache: $templateCache })
.then(function(response) {
return angular.element('
').append(response.data).find('svg')[0];
- });
- }
-
- /**
- * User did not specify a URL and the ID has not been registered with the $mdIcon
- * registry
- */
- function announceIdNotFound(id) {
- var msg;
-
- if (angular.isString(id)) {
- msg = 'icon ' + id + ' not found';
- $log.warn(msg);
- }
-
- return $q.reject(msg || id);
+ }).catch(announceNotFound);
}
/**
diff --git a/src/components/icon/iconService.spec.js b/src/components/icon/iconService.spec.js
index 98416798724..d57e8cffdf8 100644
--- a/src/components/icon/iconService.spec.js
+++ b/src/components/icon/iconService.spec.js
@@ -11,6 +11,7 @@ describe('mdIcon service', function() {
$mdIconProvider
.icon('android' , 'android.svg')
.icon('c2' , 'c2.svg')
+ .icon('notfound' ,'notfoundicon.svg')
.iconSet('social' , 'social.svg' )
.iconSet('notfound' , 'notfoundgroup.svg' )
.defaultIconSet('core.svg');
@@ -26,6 +27,7 @@ describe('mdIcon service', function() {
$templateCache.put('c2.svg' , '');
$httpBackend.whenGET('notfoundgroup.svg').respond(404, 'Cannot GET notfoundgroup.svg');
+ $httpBackend.whenGET('notfoundicon.svg').respond(404, 'Cannot GET notfoundicon.svg');
}));
@@ -104,7 +106,7 @@ describe('mdIcon service', function() {
});
describe('icon set URL is not found', function() {
- it('should throw Error', function() {
+ it('should log Error', function() {
var msg;
try {
$mdIcon('notconfigured')
@@ -119,8 +121,8 @@ describe('mdIcon service', function() {
});
});
- describe('icon is not found', function() {
- it('should throw Error', function() {
+ describe('icon group is not found', function() {
+ it('should log Error', function() {
var msg;
try {
$mdIcon('notfound:someIcon')
@@ -135,6 +137,15 @@ describe('mdIcon service', function() {
});
});
+ describe('icon is not found', function() {
+ it('should not throw Error', function() {
+ expect(function(){
+ $mdIcon('notfound');
+
+ $httpBackend.flush();
+ }).not.toThrow();
+ });
+ });
});
function updateDefaults(svg) {