Javascript Angularjs创建全局变量的动态副本
我正在用jQuery和Angular创建一个天气应用程序。简单地说,以下是我的代码:Javascript Angularjs创建全局变量的动态副本,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我正在用jQuery和Angular创建一个天气应用程序。简单地说,以下是我的代码: (function() { forecast = {}; (function($) { forecast.head = "date"; }(jQuery)(); var app = angular.module("myApp", []); var forecastController = app.controller("forecastController
(function() {
forecast = {};
(function($) {
forecast.head = "date";
}(jQuery)();
var app = angular.module("myApp", []);
var forecastController = app.controller("forecastController", function() {
this.data = forecast;
});
}());
和我的html:
<!doctype html>
<html>
<head>
...
</head>
<body ng-app="myApp">
<table ng-controller="forecastController as forecast">
<thead ng-repeat="item in forecast.data.head">
<th>{{item}}</th>
</thead>
...
</table>
</body>
</html>
然而,它没有输出任何东西。jQuery使用ajax调用来获取天气,这是异步的。如果我不使它异步,一切都会正常工作。但是,我希望它是异步的
请帮忙 我建议您在angular中进行异步ajax调用,这样您就可以更好地控制它。查找$http并为此作出承诺。@Fedaykin不幸的是,该插件是用jQuery编写的。无论如何,谢谢你。我想我必须实现一些$scope.$watch的东西,但我不知道怎么做。如果我在ajax调用中关闭async,它就可以工作了。。这比实际情况更糟variable@PSL我是初学者,你说指令是什么意思?你能给我一个链接吗?