This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tagsInput): Remove dependency on interpolation symbols
When the interpolation symbols are changed from the default ones ({{ and }}) the tagsInput directive's template is rendered invalid since it's using the default interpolation symbols. To fix that, replace that dependency with a new helper directive, tiBindAttrs, which binds attributes to properties of the scope and keep those attributes always up-to-date. Closes #151
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc directive | ||
* @name tiBindAttrs | ||
* @module ngTagsInput | ||
* | ||
* @description | ||
* Binds attributes to expressions. Used internally by tagsInput directive. | ||
*/ | ||
tagsInput.directive('tiBindAttrs', function() { | ||
return function(scope, element, attrs) { | ||
scope.$watch(attrs.tiBindAttrs, function(value) { | ||
angular.forEach(value, function(value, key) { | ||
attrs.$set(key, value); | ||
}); | ||
}, true); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
describe('bind-attrs directive', function() { | ||
var $scope, $compile, | ||
element; | ||
|
||
beforeEach(function() { | ||
module('ngTagsInput'); | ||
|
||
inject(function($rootScope, _$compile_) { | ||
$scope = $rootScope; | ||
$compile = _$compile_; | ||
}); | ||
}); | ||
|
||
function compile(value) { | ||
element = $compile('<span ti-bind-attrs="' + value + '">')($scope); | ||
$scope.$digest(); | ||
} | ||
|
||
it('sets the element attributes according to the provided parameters', function() { | ||
// Arrange | ||
$scope.prop1 = 'Foobar'; | ||
$scope.prop2 = 42; | ||
|
||
// Act | ||
compile('{attr1: prop1, attr2: prop2}'); | ||
|
||
// Assert | ||
expect(element.attr('attr1')).toBe('Foobar'); | ||
expect(element.attr('attr2')).toBe('42'); | ||
}); | ||
|
||
it('updates the element attributes when provided parameters change', function() { | ||
// Arrange | ||
$scope.prop1 = 'Foobar'; | ||
$scope.prop2 = 42; | ||
compile('{attr1: prop1, attr2: prop2}'); | ||
|
||
// Act | ||
$scope.prop1 = 'Barfoo'; | ||
$scope.prop2 = 24; | ||
$scope.$digest(); | ||
|
||
// Assert | ||
expect(element.attr('attr1')).toBe('Barfoo'); | ||
expect(element.attr('attr2')).toBe('24'); | ||
}); | ||
}); |