0

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>
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    Possible duplicate of [Pass Angular scope variable to Javascript](http://stackoverflow.com/questions/17960622/pass-angular-scope-variable-to-javascript) – FuePi Jun 03 '16 at 13:15

2 Answers2

1

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

Community
  • 1
  • 1
HarlemSquirrel
  • 8,966
  • 5
  • 34
  • 34
0

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

buggy1985
  • 919
  • 8
  • 24