我正在使用 AngularJS 和 D3.JS
我有一个 html 表单,其中包含以下内容:
<div simple-chart chart-data="lineData"></div>
这与这样的指令 Hook :
mist.directive("simpleChart", function($window, $http){
return{
restrict: "EA",
template: "<svg width='750' height='200'></svg>",
link: function(scope, elem, attrs){
function drawLineChart() {
//initilize the line chart
}
$http.get("myurl")
.success(function(data, status, headers, config){
drawLineChart();
})
}}
});
- 是否可以使用 $http.get("myurl") 中的数据创建另一个指令,而无需再次调用它?
- 是否可以使 $http.get("myurl") 变得通用,以便可以由不同的指令调用?
- 我可以使用这样的东西吗? Can't get correct return value from an jQuery Ajax call
最佳答案
您可以将 http 调用包装到服务中并使用类似 angular-cache 的内容。缓存来自服务器的响应。
关于javascript - 使用 AngularJS 在 2 个不同的指令中调用相同的 $http.get(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30772380/