Hi,

This is a race condition between compilation of transcluded content and 
jquery's append method. Adding a timeout of 0 solved the issue. I am not 
sure if this is an elegant solution. Please refer to the plunk:

http://plnkr.co/edit/Bg4ILr86lHbxzFhg41jI?p=info

Hope this helps.

Regards,

Vaibhav Gupta



On Monday, 16 November 2015 23:32:57 UTC+5:30, Christian Weber wrote:
>
> Hi @ All.
>
> Following code:
>
> <div ng-app="test" ng-controller="Main">
>     <test-directive ng-model="test">
>          <h1>{{item}}</h1>
>     </test-directive>
> </div>
> <script type="text/javascript" src="./_lib/jquery.js"></script>
> <script type="text/javascript" src="./_lib/angular.js"></script>
> <script type="text/javascript">
> angular.module('test', [])
> .controller('Main', function ($scope) {
>     $scope.test = 'Hello, World!';
> })
> .directive('testDirective', function ($compile, $sce) {
>     return {
>         restrict: 'E',
>         scope: {
>             model: '=ngModel'
>         },
>         replace: true,
>         transclude: true,
>         template: '<div style="background-color: red;" 
> ng-bind-html="content"></div>',
>         controller: function ($scope, $element, $transclude) {
>             $scope.update = function () {
>                 var scope = $scope.$new(true);
>                 scope.item = $scope.model;
>                 $scope.content = $sce.trustAsHtml($('<div>').append(
> $transclude(scope)).html());
>             };
>
>
>             $scope.update();
>             $scope.$watch('model', $scope.update);
>         }
>     };
> });
> </script>
>
>
> Why does the $transclude(scope) not replace {{item}} with the 
> corresponding value?
>
> Regards, Christian
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to