mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
feat($compile): allow directives to modify interpolated attributes
A directive can now set/update/remove attribute values even those containing
interpolation during the compile phase and have the new value be picked up
during the compilation.
For example in template:
<div replace-directive some-attr-or-directive="{{originalInterpolationValue}}"></div>
the replace-directive can now replace the value of some-attr-or-directive during compilation
which produces this intermitent template:
<div replace-directive some-attr-or-directive="{{replacedInterpolationValue}}"></div>
or even
<div replace-directive some-attr-or-directive="replacedStaticValue"></div>
as well as
<div replace-directive some-attr-or-directive></div>
This commit is contained in:
committed by
Igor Minar
parent
eb53423a41
commit
fe8d893b83
@@ -1503,6 +1503,12 @@ describe('$compile', function() {
|
||||
expect(attr.$observe('someAttr', observeSpy)).toBe(observeSpy);
|
||||
};
|
||||
});
|
||||
directive('replaceSomeAttr', valueFn({
|
||||
compile: function(element, attr) {
|
||||
attr.$set('someAttr', 'bar-{{1+1}}');
|
||||
expect(element).toBe(attr.$$element);
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
@@ -1544,6 +1550,14 @@ describe('$compile', function() {
|
||||
}));
|
||||
|
||||
|
||||
it('should allow directive to replace interpolated attributes before attr interpolation compilation', inject(
|
||||
function($compile, $rootScope) {
|
||||
element = $compile('<div some-attr="foo-{{1+1}}" replace-some-attr></div>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
expect(element.attr('some-attr')).toEqual('bar-2');
|
||||
}));
|
||||
|
||||
|
||||
it('should call observer of non-interpolated attr through $evalAsync',
|
||||
inject(function($rootScope, $compile) {
|
||||
$compile('<div some-attr="nonBound" observer></div>')($rootScope);
|
||||
|
||||
Reference in New Issue
Block a user