How to refresh the previous page using AngularJS? -
we have asp.net application use angularjs. there's page table (list) contains pictures , properties. pictures in first column of table. code looks following:
<td> <a ng-href="{{pic.fullurl}}" target="_blank"> <img class="img-thumbnail" ng-src="{{pic.fullurl}}" alt="{{pic.alttext}}" /> </a> </td>
we can edit picture clicking "edit" button , go next page (edit). after made changes, click "back" button return previous page (list).
the issue image on first page hasn't been refreshed if changed on edit page, pic.fullurl doesn't take effect.
i've tried use watch function, no luck.
how make work?
update
we have service:
pictureapp.factory('pictureservice', function ($http, $location) { var pictureservice = function () { this.tolist = function (objtype, objid, mode) { $location.path('/' + objtype + '/' + objid + '/' + mode); };
and use when accept changes on edit page in way:
$scope.accept = function () { ... query.then(function () { pictureservice.tolist($routeparams.objtype, $routeparams.objid, $routeparams.mode); }); };
as can see call tolist , go list page, without reloading.
in list's controller have this:
$scope.$watch('rbmode', function (val) { pictureservice.tolist($routeparams.objtype, $routeparams.objid, val); });
on list page have this:
<div ng-if="dataloaded"> <div ng-switch="rbmode"> <div ng-switch-when="static"> <div ng-include="'partials/pic/pictable.htm'" onload="this.pics = data;"></div> </div> <div ng-switch-when="banner"> <accordion close-others="false"> <accordion-group is-open="expandbanners" heading="{{pics[0].typedescription}}" ng-repeat="pics in data"> <div ng-include="'partials/pic/pictable.htm'" onload="this.pics = $parent.pics;" ></div> </accordion-group> </accordion> </div> </div> </div>
and pictable.htm looks following:
<tr ng-repeat="pic in pics" ng-class="{'movable-row':isbanner}"> <td>{{pic.picturelinkid}}</td> <td> <a ng-href="{{pic.fullurl}}" target="_blank"> <img class="img-thumbnail" ng-src="{{pic.fullurl}}" alt="{{pic.alttext}}" tooltip-popup-delay='1000' tooltip-placement="right" tooltip="Кликните, чтобы открыть в полном размере" /> </a> </td>
sounds have image cache issue. place timestamp parameter on end of image url "*.jpg?ts=3324324". let browser know needs refetch image once has been edited. initialize timestamp when page loads , update timestamp whenever image edited.
you can try plnkr below can observe in network panel, fetch image each time timestamp updated.
edit: updated demonstrate communication across controllers.
http://plnkr.co/edit/lp9lwkr3hgsqtit4c3n0?p=preview
<!doctype html> <html> <head> <script data-require="angular.js@*" data-semver="1.4.0-rc.1" src="https://code.angularjs.org/1.4.0-rc.1/angular.js"></script> <link rel="stylesheet" href="style.css" /> </head> <body> <div ng-controller="cntrl"> <img ng-src="{{imgurl}}'?ts={{lastedit}}" /> </div> <div ng-controller="editcntrl"> <button ng-click="updatets()">update ts</button> </div> <script> var app = angular.module("app",[]); app.controller("cntrl",function($scope){ $scope.lastedit = (new date()).gettime(); $scope.imgurl = "http://dummyimage.com/600x400/000/fff"; $scope.$on("edited",function(){ $scope.lastedit = (new date()).gettime(); }); }); app.controller("editcntrl",function($scope,$rootscope){ $scope.updatets = function(){ $rootscope.$broadcast("edited"); } }); angular.bootstrap(document,["app"]); </script> </body> </html>
Comments
Post a Comment