javascript - Issue with getting new data from http call and automatic reload -
in ionic app have 2 services studies , collections. studies makes http call json object gets json array object iterate through , display on html page. here studies service:
.factory('studies',function($http,$filter,$q){ var deferred = $q.defer(); $http.get("http://localhost/platform/loginsuccess.json").success( function(data){ // angular.copy(data, studies); deferred.resolve(data); } ); return { all: function(){ return deferred.promise; } }; })
and here controller code:
$scope.studies = []; studies.all().then(function(data) { $scope.x = angular.fromjson(data.allprojects); $scope.studies = angular.fromjson($scope.x.list); });
this how displayed in html:
<div class="feed-item" ng-repeat="study in studies"> <div class="feed-media"> <img src="http://www.speedhunters.com/wp-content/uploads/2013/12/lamborghini-hurac%c3%a1n-lp610-4-01_n3-1200x800.jpg" class="feed-image"> <div class="feed-gradient-overlay"></div> <a href="#/app/studies/{{study.noderef}}"><h4 class="feed-title">{{study.title}}</h4></a>z </div> </div>
study.noderef extracted in same controller , fetched function calls service using noderef.
scope.nodeid = $stateparams.studynoderef; $scope.collection = []; collections.fetchcollection($scope.nodeid).then(function(data){ $scope.y = angular.fromjson(data.list); $scope.collections = angular.fromjson($scope.y[0].collections); });
here collections service:
.factory('collections', ['$q', '$http', function($q, $http) { return { fetchcollection: function(collectionid) { var deffered = $q.defer(); $http({ method: 'post', url: 'http://localhost/platform/project/fetch.json', params: { 'noderef': collectionid } }).success(function(data) { deffered.resolve(data); }); return deffered.promise; } }; }])
then iterate through collections in menu.html page side menu present in templates:
<ion-list ng-controller="navigationctrl" ng-repeat="collection in collections"> <ion-item nav-clear menu-close ng-click="go('app.studies')" class="item item-icon-left brand-base-text-color"> <i class="icon ion-ios-paper"></i> {{collection.name}} </ion-item>
now when click on study on studies.html page redirects appropriate #/app/studies/{{study.noderef}} however, side menu doesn't update collections on side menu after refresh it. both study , collections service under same controller called appctrl. how collections reload automatically based on appropriate noderef of study?
edit:
here code have in app.js file studies,study , menu(where iteration collections done). can seen use same controller called appctrl:
.state('app', { url: "/app", abstract: true, templateurl: "templates/rubyonic/menu.html", controller: 'appctrl', reload: true }) .state('app.studies', { url: "/studies", views: { 'menucontent': { templateurl: "templates/rubyonic/studies.html", controller: 'appctrl', reload: true } } }) .state('app.study', { url: "/studies/:studynoderef", views: { 'menucontent': { templateurl: "templates/rubyonic/overview.html", controller: 'appctrl', reload: true } } })
Comments
Post a Comment