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

fix(chips): do not display broken image when no image is provided #4851

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/components/chips/contact-chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ describe('<md-contact-chips>', function() {
expect(ctrl.highlightFlags).toEqual('i');
});

it('renders an image element for contacts with an image property', function() {
scope.contacts.push(scope.allContacts[2]);

var element = buildChips(CONTACT_CHIPS_TEMPLATE);
var ctrl = element.controller('mdContactChips');
var chip = angular.element(element[0].querySelector('.md-chip-content'));

expect(chip.find('img').length).toBe(1);
});

it('does not render an image element for contacts without an image property', function() {
var noImageContact = scope.allContacts[2];
delete noImageContact.image;
scope.contacts.push(noImageContact);

var element = buildChips(CONTACT_CHIPS_TEMPLATE);
var ctrl = element.controller('mdContactChips');
var chip = angular.element(element[0].querySelector('.md-chip-content'));

expect(chip.find('img').length).toBe(0);
});

describe('filtering selected items', function() {
it('should filter', inject(function() {
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
Expand Down
6 changes: 4 additions & 2 deletions src/components/chips/js/contactChipsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ var MD_CONTACT_CHIPS_TEMPLATE = '\
<div class="md-contact-suggestion">\
<img \
ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
alt="{{item[$mdContactChipsCtrl.contactName]}}" />\
alt="{{item[$mdContactChipsCtrl.contactName]}}"\
ng-if="item[$mdContactChipsCtrl.contactImage]" />\
<span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText"\
md-highlight-flags="{{$mdContactChipsCtrl.highlightFlags}}">\
{{item[$mdContactChipsCtrl.contactName]}}\
Expand All @@ -81,7 +82,8 @@ var MD_CONTACT_CHIPS_TEMPLATE = '\
<div class="md-contact-avatar">\
<img \
ng-src="{{$chip[$mdContactChipsCtrl.contactImage]}}"\
alt="{{$chip[$mdContactChipsCtrl.contactName]}}" />\
alt="{{$chip[$mdContactChipsCtrl.contactName]}}"\
ng-if="$chip[$mdContactChipsCtrl.contactImage]" />\
</div>\
<div class="md-contact-name">\
{{$chip[$mdContactChipsCtrl.contactName]}}\
Expand Down