zoukankan      html  css  js  c++  java
  • angularjs图片上传后不刷新的解决办法

    刚接触angularjs在使用的过程中遇到这个问题

    首先我们的图片地址是根据ID来获取的,所以用了指令来完成图片的绑定

    .directive("cImg", ['appUrl', function (appUrl) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                var url = appUrl+ "/GetImgUrl";
                var para = { id: attrs.id};
                scope.baseService.post(url, para, function (data) {
                    $(element).attr("src", data.d);
                });
            }
        };
    }])
    

      

     <img c-img id="{{id}}" width="200" height="120" alt="">
    

     

    但是这样的话上传图片后如果不刷新页面的话图片地址是不会更新的,解决方法是用一个$scope变量来记录是否显示图片,这样在更新这个变量后就会刷新图片了

    <img ng-if="IsShowImg" c-img id="{{id}}" width="200" height="120" alt="">
    

      

     function () {
            var url = url+ "/up_load";
            //上传之前设置为false  隐藏图片
            $scope.IsShowImg=false;
            $scope.baseService.post(url, {}, function (data) {
                //上传成功后显示图片
                $scope.IsShowImg = true;
            });
        }
    

      

  • 相关阅读:
    System.IO.MemoryStream.cs
    System.IO.Stream.cs
    System.Web.HttpContext.cs
    System.Text.Encoding.cs
    System.Web.HttpRuntime.cs
    System.Web.Caching.Cache.cs
    System.Diagnostics.Stopwatch.cs
    FrameBuffer
    Java实现 洛谷 P1422 小玉家的电费
    Java实现 洛谷 P1422 小玉家的电费
  • 原文地址:https://www.cnblogs.com/zhuwenjun/p/4673973.html
Copyright © 2011-2022 走看看