Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(popover): use expression to fix usage with $sce
Browse files Browse the repository at this point in the history
Allows for trusted resource URLs through Strict Contextual Escaping ($sce).
If an interpolated expression is used instead, then the benefits of SCE is
lost.

Fixes #3558
  • Loading branch information
chrisirhc authored and rvanbaalen committed Apr 29, 2015
1 parent d867f83 commit 422c823
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/popover/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h4>Dynamic</h4>
</div>
<button popover="{{dynamicPopover.content}}" popover-title="{{dynamicPopover.title}}" class="btn btn-default">Dynamic Popover</button>

<button popover-template="{{dynamicPopover.templateUrl}}" popover-title="{{dynamicPopover.title}}" class="btn btn-default">Popover With Template</button>
<button popover-template="dynamicPopover.templateUrl" popover-title="{{dynamicPopover.title}}" class="btn btn-default">Popover With Template</button>

<script type="text/ng-template" id="myPopoverTemplate.html">
<div>{{dynamicPopover.content}}</div>
Expand Down
6 changes: 4 additions & 2 deletions src/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] )
return {
restrict: 'EA',
replace: true,
scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&',
scope: { title: '@', contentExp: '&', placement: '@', animation: '&', isOpen: '&',
originScope: '&' },
templateUrl: 'template/popover/popover-template.html'
};
})

.directive( 'popoverTemplate', [ '$tooltip', function ( $tooltip ) {
return $tooltip( 'popoverTemplate', 'popover', 'click' );
return $tooltip( 'popoverTemplate', 'popover', 'click', {
useContentExp: true
} );
}])

.directive( 'popoverPopup', function () {
Expand Down
16 changes: 15 additions & 1 deletion src/popover/test/popover-template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('popover template', function() {

beforeEach(inject(function($rootScope, $compile) {
elmBody = angular.element(
'<div><span popover-template="{{ templateUrl }}">Selector Text</span></div>'
'<div><span popover-template="templateUrl">Selector Text</span></div>'
);

scope = $rootScope;
Expand Down Expand Up @@ -62,5 +62,19 @@ describe('popover template', function() {

expect( elmBody.children().eq(1).text().trim() ).toBe( 'new text' );
}));

it('should hide popover when template becomes empty', inject(function ($timeout) {
elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );

scope.templateUrl = '';
scope.$digest();

expect( tooltipScope.isOpen ).toBe( false );

$timeout.flush();
expect( elmBody.children().length ).toBe( 1 );
}));

});

2 changes: 1 addition & 1 deletion template/popover/popover-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="popover-inner">
<h3 class="popover-title" ng-bind="title" ng-if="title"></h3>
<div class="popover-content"
tooltip-template-transclude="content"
tooltip-template-transclude="contentExp()"
tooltip-template-transclude-scope="originScope()"></div>
</div>
</div>

0 comments on commit 422c823

Please sign in to comment.