Service data in a nested form when loading using ui-router

On the Angular app home page, I have a view and a subview (see ui-router code below). For presentation, I call a call $httpto my database and outputting the results with ng-repeat. At the same time, I push these results to the service. In the nested view, I call one result from the service and display it (I use two controllers). My problem is that I need all this to happen on boot. Is the “solution” in u-router the best way to get closer to this?

  $urlRouterProvider.otherwise('/open');
  $urlRouterProvider.when('/open', '/open/mainbook');
  $stateProvider
  .state('open', {
  url: '/open',
  templateUrl: 'ang/views/open.html',
})

 .state('open.mainbook', {
  url: '/{featId}',
  templateUrl: 'ang/views/open.mainBook.html',
  })`
+4
source share
1 answer

, , $http $state.go ( ), .. $scope.featCall = function () { $http({ method: 'GET', cache: 'true', url: '/featList' }).then(function (result) { $scope.single = []; $scope.single = result.data[0]; $state.go('open.mainbook', { featId: $scope.single.id }); bookData.clearProduct(); angular.forEach(result.data, function (eachOne) { $scope.featList.push(eachOne); bookData.addProduct(eachOne); }) }) };

, (bookData) , .

0

Source: https://habr.com/ru/post/1650423/


All Articles