We got stuck in a situation where we are unable to get a scope variable 
value from a link function of custom directive to an application Controller 
in angularJS.

Below is the custom directive code:

oxadminApp.directive("test", ['$compile',
    function($compile){

        return {
          restrict: 'A',
  link: function(scope, element, attrs){
            element
            .on('click',function(){
              var newAnchorEle;
 var anchorTagText = $('#taskName').val();
 scope.anchorText= anchorTagText; 
              //  make the new element
              newAnchorEle = document.createElement('a');
              angular.element(newAnchorEle)
 .attr('ui-sref', 'TaskLinks.CaptureTaskData')
 .attr('id', anchorTagText)
               .text(anchorTagText)
  .bind('click', function(anchorText){
$('.add_metadata ').show();
// scope.anchorText = anchorTagText;
  });

              //  append it in the parent element
              $('#taskList').append(newAnchorEle);
              //  compile the new HTML
              $compile(newAnchorEle)(scope);
            });
          }


The scope.anchorText variable value in the link funtion should be accessed 
in one of my application controller, so that this can be used as a 
reference to compare an array in my controller.

the controller code looks like below:

oxadminControllers.controller('CaptureTaskController', ['$scope', 
'$rootScope', function($scope, $rootScope){

      //should access the scope. anchorText  value here in this controller.


}]); 


Please suggest some solution to the above query.


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