angularjs - Angular nested resources data -


i have following code:

//routes  .state('app.parent', {    url: '/parent',    templateurl: 'parent.html',    controller: 'parentctrl'  })  .state('app.parent.child', {    url: '/child',    controller: 'childctrl',    templateurl: 'child.html',  })      //controllers  .controller('parentctrl', ['$scope', 'someresource', function ($scope, someresource) {    $scope.resources = [];        someresource.query({}, function(data) {      $scope.resources = data;    });  }])  .controller('childctrl', ['$scope', 'otherresource', function ($scope, otherresource) {    $scope.other = {};    ...  }])
<!-- viewss -->  <!-- parent.html -->  ...  <div ui-view>    <table class="table table-hover table-striped">      <tbody>        <tr ng-repeat="resource in resources">          ...        </tr>      </tbody>    </table>  </div>    <!-- child.html -->  <div class="form">  	...  </div>

and, other nested states.

the problem when access "child" state of "parent", parent controller apparently executed, call someresource.query called every child state.

i need query parent not child state, , need nested.

what doing wrong?

as per angular-ui docs,

when application in particular state—when state "active"—all of ancestor states implicitly active well. below, when "contacts.list" state active, "contacts" state implicitly active well, because it's parent state "contacts.list".

which means if don’t need parent active when child accessed, don’t use nesting. (your url structure lacks nesting might sign don’t need in state structure.)

if want nest states other reasons, , want avoid expensive query running more once, might want refactor someresource implementation. example, can add caching within service repeat calls query() don’t cause overhead.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -