javascript - View only works the first time in Angular -
i have app , utilizing routes load 2 different views.
the first route #/ main list view. works every time.
my second route #/view/:id , loads second view when list item clicked.
the view data driven based off id, of need make $http requests through service created.
is possible when leave #/view/:id route, unloads view , reloads when come back?
or
how go resetting promises inside service next time view loaded, request new data?
these not mutually exclusive questions. routing ngview destroys view, scope, , controller on every load, controller , scope history not preserved among routes. otherwise, memory load in browser high; instead, can use services preserve state need across routes.
$http requests made fresh every time called, unless cache option enabled. there shouldn't work required work designed:
.factory( 'dataservice', function( $http ) { return function dataservicefn ( id ) { return $http.get( '/myapi', { params: { id: id } } ); }; }); when data service called (e.g. dataservice( $routeparams.id ); ), new promise returned.
this sample service structure incredibly simple case, long $http call made fresh on each service call, new promise guaranteeing fresh data every time.
Comments
Post a Comment