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

2 Answers 2

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

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.

2
  • how to use this variable globalScope in javascript can you please explain it i want top use it in $(# HERE) Commented Jun 3, 2016 at 13:00
  • Try with $("#"+globalScope.prentId)
    – buggy1985
    Commented Jun 3, 2016 at 13:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.