2

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**
});
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Michael Meritt
  • 383
  • 5
  • 18
  • 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 '16 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 '16 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 '16 at 06:02

1 Answers1

1

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

Vladimir Furso
  • 338
  • 1
  • 10
  • 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 '16 at 21:48
  • `app.controller("controller", function($scope, $rootScope, $http, $window) { console.log('initilaized!'); $scope.PlayerList = $window.FinalP; });` – Vladimir Furso Mar 30 '16 at 21:50
  • Even accessing a simple string or int always returns undefined, but no syntax complains. hmm – Michael Meritt Mar 30 '16 at 22:49