Search code examples
jqueryangularjsglobal-variablesrootscopeangularjs-rootscope

use variable in both JQuery in an angularJS


I need to use an array that is being defined in a JQuery script inside of an angularJS controller script. I don't understand how $rootScope fits into this whole thing.

Is this possible, Any advice?

$(document).ready(function(){ 
    $.get("KIP.xml",{},function(xml){

        // I need this accessible in controller.js
        FinalP = [ ];

    }
})

..

var app = angular.module("KIdash", []);

app.controller("controller", function($scope, $rootScope, $http) {

    console.log('initilaized!');

    $scope.PlayerList = **FinalP**
});

Solution

  • You can pass variables with $window object https://docs.angularjs.org/api/ng/service/$window

    In Jquery window.FinalP = []

    in Angular $scope.SomeVar = $window.FinalP