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

Commit 315ea48

Browse files
Frank3KThomasBurleson
authored andcommitted
fix(chips): do not display broken image when no image is provided
When no image property is defined on the user model, do not render an `img`-element. * add missing unit tests for image / no image cases on contact chips Refs #4779. Closes #4851.
1 parent 35e2f2a commit 315ea48

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/components/chips/contact-chips.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ describe('<md-contact-chips>', function() {
6060
expect(ctrl.highlightFlags).toEqual('i');
6161
});
6262

63+
it('renders an image element for contacts with an image property', function() {
64+
scope.contacts.push(scope.allContacts[2]);
65+
66+
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
67+
var ctrl = element.controller('mdContactChips');
68+
var chip = angular.element(element[0].querySelector('.md-chip-content'));
69+
70+
expect(chip.find('img').length).toBe(1);
71+
});
72+
73+
it('does not render an image element for contacts without an image property', function() {
74+
var noImageContact = scope.allContacts[2];
75+
delete noImageContact.image;
76+
scope.contacts.push(noImageContact);
77+
78+
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
79+
var ctrl = element.controller('mdContactChips');
80+
var chip = angular.element(element[0].querySelector('.md-chip-content'));
81+
82+
expect(chip.find('img').length).toBe(0);
83+
});
84+
6385
describe('filtering selected items', function() {
6486
it('should filter', inject(function() {
6587
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {

src/components/chips/js/contactChipsDirective.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ var MD_CONTACT_CHIPS_TEMPLATE = '\
6969
<div class="md-contact-suggestion">\
7070
<img \
7171
ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
72-
alt="{{item[$mdContactChipsCtrl.contactName]}}" />\
72+
alt="{{item[$mdContactChipsCtrl.contactName]}}"\
73+
ng-if="item[$mdContactChipsCtrl.contactImage]" />\
7374
<span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText"\
7475
md-highlight-flags="{{$mdContactChipsCtrl.highlightFlags}}">\
7576
{{item[$mdContactChipsCtrl.contactName]}}\
@@ -81,7 +82,8 @@ var MD_CONTACT_CHIPS_TEMPLATE = '\
8182
<div class="md-contact-avatar">\
8283
<img \
8384
ng-src="{{$chip[$mdContactChipsCtrl.contactImage]}}"\
84-
alt="{{$chip[$mdContactChipsCtrl.contactName]}}" />\
85+
alt="{{$chip[$mdContactChipsCtrl.contactName]}}"\
86+
ng-if="$chip[$mdContactChipsCtrl.contactImage]" />\
8587
</div>\
8688
<div class="md-contact-name">\
8789
{{$chip[$mdContactChipsCtrl.contactName]}}\

0 commit comments

Comments
 (0)