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

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**
});
share|improve this question
    
Don't do this, don't pass variables from jQuery to Angular. If you want to use $.get, why don't you use Angular's $http.get? – emil.c Mar 30 at 21:20
    
I had a lot of trouble using only Angular... The JQuery style was the first to even successfully load the file.. Perhaps I should go back and try again. – Michael Meritt Mar 30 at 22:11
    
If you want to use angular, I suggest you read Angular up & running, which I believe is one of the best books out there about angular. If you have just started using angular and not sure if it's the right choice, I'd suggest looking into ReactJS instead. – emil.c Mar 31 at 6:02
up vote 1 down vote accepted

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

share|improve this answer
    
Awesome Thanks. Its working somewhat already. I can see the object in console.log(obj) in my Jquery section, but in angular it remains undefined in all manners of reference. Could there be something I need to do in order to qualify $window ? > console.log("typed array " + $window.PlayerStats); > console.log("adopted from FinalP "+ $window.PlayerStatW); > console.log("direct to FinalP " +$window.FinalP); – Michael Meritt Mar 30 at 21:48
    
app.controller("controller", function($scope, $rootScope, $http, $window) { console.log('initilaized!'); $scope.PlayerList = $window.FinalP; }); – Vladimir Furso Mar 30 at 21:50
    
Even accessing a simple string or int always returns undefined, but no syntax complains. hmm – Michael Meritt Mar 30 at 22:49

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.