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

Commit

Permalink
fix(filter): interpolated params w/ scope aren't possible starting AJ…
Browse files Browse the repository at this point in the history
…S1.3

BREAKING CHANGE: Since filters are stateless and have no access to its scope anymore (see angular/angular.js@8863b9d), a context must be given explicitly. This removes the feature of an interpolation based on the scope (context), even without the $rootScope.

However, the feature will still work in AJS <=1.2, so we won't remove it completely yet. Handle the feature as slightly deprecated.
  • Loading branch information
knalli committed Sep 18, 2014
1 parent bffbf04 commit 9465318
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/unit/filter/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,22 @@ describe('pascalprecht.translate', function () {
expect(value[6]).toEqual('55');
});

it('should replace interpolate directive on element with given values', function () {
var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: "{value: foo}"}}</div>'))($rootScope);
$rootScope.$digest();
expect(element.html()).toEqual('Lorem Ipsum bar');
});
if (angular.version.major === 1 && angular.version.minor <= 2) {
// Until and including AJS 1.2, a filter was bound to a context (current scope). This was removed in AJS 1.3
it('should replace interpolate directive on element with given values', function () {
var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: "{value: foo}"}}</div>'))($rootScope);
$rootScope.$digest();
expect(element.html()).toEqual('Lorem Ipsum bar');
});
} else {
it('should replace interpolate directive on element with given values', function () {
$rootScope['__this'] = {value: 'bar'};
var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: __this}}</div>'))($rootScope);
$rootScope.$digest();
expect(element.html()).toEqual('Lorem Ipsum bar');
$rootScope['__this'] = undefined;
});
}
});

describe('additional interpolation', function () {
Expand Down

0 comments on commit 9465318

Please sign in to comment.