-
Notifications
You must be signed in to change notification settings - Fork 27.5k
templateURL in directive breaks interpolation in $observe #1941
Comments
this does look like a weird bug. I debugged it a bit and the reason why this is happening is that the testDir directive is observing different instane of |
ok, here is the culprit: Line 941 in 649b892
we should be calling does anybody want to take it from here and write a test for this and send a PR? |
Hi, I can't make the this test catch the bug, It passed but I think it's about letting the $rootScope.$apply() do the compilation. Any directions are gladly appreciated :) it('should support $observe inside link function on directive object', function(){
module(function() {
directive('testLink', valueFn({
link: function(scope, element, attrs) {
attrs.$observe( 'testLink', function ( val ) {
scope.testAttr = val;
});
}
}));
});
inject(function($compile, $rootScope) {
element = $compile('<div test-link="{{1+2}}">{{testAttr}}</div>')($rootScope);
$rootScope.$apply(); //what's the right way to process the directive?
expect(element.text()).toBe('3');
});
}); |
@iknite you have to use templateUrl in your testLink directive |
...
|
Directives was observing different instances of Attributes than the one that interpolation was registered with because we failed to realize that the compile node and link node were the same (one of them was a wrapper rather than raw node) Closes angular#1941
Directives was observing different instances of Attributes than the one that interpolation was registered with because we failed to realize that the compile node and link node were the same (one of them was a wrapper rather than raw node) Closes #1941
This issue comes back (plunker) when you add |
Hmm.. OK, we'll investigate. |
The bug also occus when templateUrl is used with ng-repeat directive (even when replace:true is NOT used) In the plunker, add an ng-repeat like ng-repeat="task in tasks" div test-dir ... You'll see it will break the interpolation in $observe |
Any news on this issue? This got me pretty stuck, and no simple workaround seems to be possible :) |
So far, I don't use templateUrl but template. You have to write your HTML template within the javascript file (not very clean) but it works... |
This still doesn't work with templateUrl. I inject $interpolate, and do that: scope.arg = $interpolate(attrs.arg)(scope); |
Thanks for the tip @fsobczak, I'm bummed we still have to hack this. |
Still nothing for this problem? I can still not use templateUrls because of this.. |
I drop back into the Plunkr every few weeks to see if it works with the latest version (stable or dev). No luck yet. :( |
…rve when using a templateUrl for a directive. http://plnkr.co/edit/xJNt918gEpuXR026VuZB?p=preview illustrates the issue that was fixed
I'm using replace:true, templateUrl in a directive that is inside ng-repeat. Having this issue. AlgularJS 1.0.7. I'm using $parse inside the directive to workaround this. |
Any news on a fix for this? If the fix is not forthcoming is there a workaround for the problem that allows us to keep using templateUrl? If so would someone be able to explain it? |
OK, I managed to work around the issue myself by interpolating the attributes when I needed them. I've updated the Plunker to show the fix: |
When this issue is gonna fixed? |
This is currently working in master. Here's a plunker with a recent build from our CI server: http://plnkr.co/edit/hlRvhR8uzZF6P02iEBYa?p=preview If I'm incorrect and the issue still persists, I'd be happy to re-open this. |
Sweet! Thanks for the update @btford! |
When using the
templateUrl
property,attrs.$observe
will no longer interpolate values. See the following example (also in this plunker):This will work if either (a)
template
is used instead oftemplateUrl
; or (b) an isolate scope with an '@' binding is used instead.I cannot explain this behavior, so I am opening this issue. Thanks!
The text was updated successfully, but these errors were encountered: