Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am working on a project in this i have to use a function for taging a friend in Angular JS ng-repeat and the function is written on javascript so i am confused that i want to pass id which is belong to angular js variablr called c.Parent.id and i want to use that in javascript function here is my function

 <script>

  $(document).ready(function()
  {
        var start=/@/ig;
        var word=/@(\w+)/ig;

    $("# -->>> HERE I WANT TO USE THAT ANGULAR JS VARIABLE <<<--").live("keyup",function() 
    {
        var content=$(this).text();
        var go= content.match(start);
        var name= content.match(word);
        var dataString = 'searchword='+ name;

        if(go.length>0)
        {
            $("#msgbox").slideDown('show');
            $("#display").slideUp('show');
            $("#msgbox").html("Type the name of someone or something...");
            if(name.length>0)
            {
                $.ajax({
                        type: "POST",
                        url: "<?php echo base_url(); ?>index.php/ItemDetail/getfriends",
                        data: dataString,
                        cache: false,
                        success: function(html)
                        {
                            $("#msgbox").hide();
                            $("#display").html(html).show();
                        }
                });

            }
        }
        return false();
    });

    $(".addname").live("click",function() 
    {   

        var username=$(this).attr('title');
        var id=$(this).attr('name');
        var old=$("#685").html();
        var content=old.replace(word,""); 
        $("# -->>> HERE I WANT TO USE THAT ANGULAR JS VARIABLE <<<--").html(content);
        var E="<a class='red' contenteditable='false' href='<?php echo base_url(); ?>index.php/user/wall/"+id+"' >"+username+"</a>";
        $("# -->>> HERE I WANT TO USE THAT ANGULAR JS VARIABLE <<<--").append(E);
        $("#display").hide();
        $("#msgbox").hide();
        $("# -->>> HERE I WANT TO USE THAT ANGULAR JS VARIABLE <<<--").focus();
    });

});

</script>
share|improve this question
1  
Possible duplicate of Pass Angular scope variable to Javascript – FuePi Jun 3 '16 at 13:15
up vote 1 down vote accepted

I think you can do it like this.

var scope = angular.element($("#outer")).scope();
    scope.$apply(function(){
        scope.msg = 'Superhero';
    })

Source: AngularJS access scope from outside js function

share|improve this answer

$scope variables are only available within the AngularJS Controller. If you really need to mix jQuery logic with AngularJS, then you could assign the value of your variable to a global variable.

var globalScope = {};

app.controller('MyCtrl',function($scope)) {
   globalScope.prentId = $scope.c.Prent.id;
}

But my advice would be to put your application logic in the AngularJS Controller and don't mix it with jQuery.

share|improve this answer
    
how to use this variable globalScope in javascript can you please explain it i want top use it in $(# HERE) – Rashid Hussain Jun 3 '16 at 13:00
    
Try with $("#"+globalScope.prentId) – big_p Jun 3 '16 at 13:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.