【发布时间】:2016-03-31 05:03:16
【问题描述】:
我需要使用在 angularJS 控制器脚本内的 JQuery 脚本中定义的数组。我不明白 $rootScope 是如何融入整个事情的。
这可能吗,有什么建议吗?
$(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**
});
【问题讨论】:
-
不要这样做,不要将变量从 jQuery 传递给 Angular。如果你想使用 $.get,为什么不使用 Angular 的 $http.get?
-
我只使用 Angular 时遇到了很多麻烦... JQuery 样式甚至是第一个成功加载文件的样式。也许我应该回去再试一次。
-
如果你想使用 Angular,我建议你阅读 Angular up & running,我相信这是最好的关于 Angular 的书籍之一。如果你刚刚开始使用 angular 并且不确定它是否是正确的选择,我建议你改用 ReactJS。
标签: jquery angularjs global-variables rootscope angularjs-rootscope