angular指令处理http请求

 未知的明天 发布于 2023-01-20 13:23

我有角度指令,接受url获取远程数据:

...

指令本身:

app.directive('myTag', ['$http', function($http) {
return {
    restrict: 'E',
    transclude: true,
    replace: true,  
    //template: '
{{imgres.isUrl}}\'/>
', scope:{ src:"@", //source AJAX url to dir pictures }, controller:function($scope){ console.info("enter directive controller"); $scope.gallery = []; $http.get($scope.src).success(function(data){ console.info("got data"); $scope.gallery.length = 0; $scope.gallery = data; }); } }

一般来说它可以工作,我可以在FireBug控制台中看到:

enter directive controller
GET http://127.0.0.1/srv1
got data

但是,如果我将指令的第二个实例绑定到另一个url:

...

仅适用于以下日志:

enter directive controller
GET http://127.0.0.1/srv1
enter directive controller
GET http://127.0.0.1/srv2
got data             <-- as usual it relates to first directive

难道你不能帮我解决2指令的问题

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有