Hi Sander,
I agree with you but the scenario here is we are to create an anchor tag
dynamically on UI and trying to access the text of that anchor tag at the
time of its creation.
There will be multiple such anchor tags that gets created on click of a
button. And as it is not statically present on the DOM , not able to access
the data of it in controller directly. This anchor tag that we are creating
just has text on it and ui-sref atteribute. It doesn't have any id or class
attributes tied to it.
So I need the text property of it to be accessed in my application
controller as a reference to manipulate it with an array present in my
controller.
Thanks,
Nitin
On Thursday, 6 August 2015 16:57:54 UTC+5:30, Nitin Tomer wrote:
>
> 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.