的$成功后Angularjs运行指令HTTP [英] Angularjs run directive after success of $http

查看:119
本文介绍了的$成功后Angularjs运行指令HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义的指令键,当一些添加/从NAV我想反映在该资产净值变化删除任何一个导航。如果资产净值来自范围那么我可以更新范围,而资产净值来自指令,所以我不知道如何来调用 $ HTTP 成功的指令。

I am making a nav using custom directive and when some add/remove anything from that nav I wanted to reflect changes on that nav . If that nav comes from scope then I can update scope but as nav comes from directive so I don't know how to call that directive on $http success.

下面是我的指令:

< nav_toolbar UUID = \\PK \\我的法= \\get_navs \\>< / nav_toolbar>

在这里你可以看到我使用的一些属性太指令,它可以帮助我获取准确的导航选项。

Here you can see I am using some attributes too in directive which helps me to fetch exact nav options.

指令code:

app.directive('synapseToolbar', function() {
   var controller = ['$scope', '$element', '$attrs', '$http', '$compile','Scopes',
        function ($scope, $element, $attrs, $http, $compile, Scopes) {
        var uuid = $scope.uuid
        // my $http request comes here 
        // on $http success i'll set this below scope    
            $scope.synapse_toolbar_icons = a object
      }];
  return {
    restrict: 'EA',
    scope: {
      uuid: '=',
      method: '&myMethod',
    },
    controller: controller,
    link: function (scope, element, attrs) {
            var click_fn = scope.method();
             $(element).click(function(e, rowid) {
              click_fn(scope.link_source, scope.link_fact_type);
            });
          },
    template: '<div ng-show="synapse_toolbar_icons" ng-repeat="toolbar in synapse_toolbar_icons" class="tile iconSizeClass synapse-toolbar bg-crimson ng-scope" data-toggle="tooltip" ng-click="bindData(toolbar.link_source, toolbar.link_fact_type)">'+
              '<div dynamic="toolbar.icon_html"></div>'+
              '</div>',
  };
});

功能上,我要再次呼吁指令

$scope.remove_synapse_link = function(){

        $http({
                method : 'POST',
            }).success(function(data,status){
                // here I want to call that directive again 
            })
            .error(function(data,status){
                    $.notify("Something went wrong while adding dislike", "error");
            }); 
    }

Plunker http://plnkr.co/edit / FpzGkIpBPfOnoFrwQkmj?p = preVIEW

推荐答案

$ HTTP是返回一个承诺,$ HTTP是异步的,在那里,当你的HTML渲染你做什么DONOT渲染HTML,除非并直到你不会响应指令运行

$http is returns a promise and $http is asynchronous and where directive runs when your html renders what you do is donot render html unless and untill you will not response

例如

<div ng-if="flag"> 
<div my-custom-directive></div>
</div>

控制器部件

$scope.flag=false;

$http(//send request).success(function(){
$scope.flag=true
});

伍,如果总是创建HTML时,条件成真
我的东西这件事情会帮助你。它为我工作

Ng-if always create html when condition become true I thing this thing will help you.. It worked for me

这篇关于的$成功后Angularjs运行指令HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆