I would basically add a 'message' attribute as follows: <my-directive 
message="message">
That way your local scope will be bound to the "message" variable of 
whatever scope your directive is used in.
Then you would not need the link function.




On Monday, June 22, 2015 at 4:10:17 AM UTC-7, Pete Bacon Darwin wrote:
>
> The transcluded content is bound to the scope in which the directive 
> lives, not the isolated scope. So `message` is not available there.
>
> On 21 June 2015 at 05:22, Thiago Rizzo <[email protected] <javascript:>> 
> wrote:
>
>> Hello, 
>>
>> I just made an example of how I am trying to use transclude data binding. 
>> Well, after binding an object (message) from controller scope its 
>> "undefined" in link function. 
>>
>> <html ng-app="myApp">
>>  <head>
>>  <script src="
>> https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js";
>> ></script>
>>
>>
>>  <script>
>>  angular.module('myApp', []).controller('myAppController', function(
>> $scope)
>>  {
>>  $scope.message = { text: 'hello'}
>>  });
>>
>>
>>  angular.module('myApp').directive('myDirective', function() {
>>             return {
>>  restrict: 'E',
>>         template: "<div><div ng-transclude></div></div>",
>>         transclude: true,
>>         scope: { message: "=" },
>>         link: function (scope) {
>>          // Its "undefined" here
>>          console.log(scope.message);
>>         }
>>     };
>>  })
>>  </script>
>>
>>
>>  </head>
>>
>>
>>  <body ng-controller="myAppController">
>>       <my-directive>
>>            {{message.text}}
>>        <my-directive>
>>  </body>
>> </html>
>>
>>
>> Any help would be appreciated, Thanks
>>
>> Regards, Thiago Rizzo
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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