Skip to content

Commit

Permalink
fix (filter): Pass scope object to parse getter
Browse files Browse the repository at this point in the history
Pass `this` (= current scope) to parse getter. It execute expressions in scope
  • Loading branch information
tamtakoe committed Apr 21, 2014
1 parent 61fc089 commit 64cfde6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/filter/translate.js
Expand Up @@ -53,7 +53,7 @@ angular.module('pascalprecht.translate')
return function (translationId, interpolateParams, interpolation) {

if (!angular.isObject(interpolateParams)) {
interpolateParams = $parse(interpolateParams)();
interpolateParams = $parse(interpolateParams)(this);
}

return $translate.instant(translationId, interpolateParams, interpolation);
Expand Down
13 changes: 11 additions & 2 deletions test/unit/filter/translate.spec.js
Expand Up @@ -20,13 +20,16 @@ describe('pascalprecht.translate', function () {
.preferredLanguage('en');
}));

var $filter, $q, $rootScope, $translate;
var $filter, $q, $rootScope, $translate, $compile;

beforeEach(inject(function (_$filter_, _$q_, _$rootScope_) {
beforeEach(inject(function (_$filter_, _$q_, _$rootScope_, _$compile_) {
$filter = _$filter_;
$q = _$q_;
$rootScope = _$rootScope_;
$translate = $filter('translate');
$compile = _$compile_;

$rootScope.foo = 'bar';
}));

it('should be a function object', function () {
Expand Down Expand Up @@ -80,6 +83,12 @@ describe('pascalprecht.translate', function () {
expect(value[5]).toEqual('10');
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');
});
});

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

0 comments on commit 64cfde6

Please sign in to comment.