访问使用notify false解析$ state.go()上的数据

时间:2015-03-25 11:02:01

标签: javascript angularjs angular-ui-router

我有一个交互式地图,其中包含类别和标记。 我还有一个搜索表单,允许用户搜索标记。

当用户点击他想要显示的结果时,我想:

  1. 将网址更改为相关类别网址
  2. 显示与标记
  3. 相关的类别
  4. 打开弹出式标记
  5. 这是代码。

    route.js

    $stateProvider
        .state('app', {
            url: '',
            abstract: true,
            templateUrl: basepath('app.html'),
            controller: 'AppController'
        })
        .state('app.category', {
            url: '/c-{categoryId}',
            templateUrl: basepath('pages/category.html'),
            controller: 'categoryController',
            resolve: {
                apiRequest: function($http, $stateParams) {
                    return $http.get(App.API_URL + "category/" + $stateParams.categoryId);
                }
            }
        })
    ;
    

    searchController.js

    app.controller('searchController', ['$scope', '$state',
        function ($scope, $state) {
        'use strict';
    
        // callback when the user click on a marker in the search box
        $scope.onSearchSelect = function ($item) {
            $state.go('app.category', {
                categoryId: $item.categoryId
            }, {
                location: "replace",
                inherit: false,
                notify: false
            }).then(function(response) {
                // response
                // would like to access apiRequest data here
                // to display the category + markers + open the popup
            });
        };
    }]);
    

    一切正常,URL被更改,API被调用等... 唯一的问题是我不知道如何从apiRequest解析器中检索API数据(由#34; app.category"路由调用)

    如果您有任何线索,或者我做错了什么,请帮助我:)

    谢谢!

0 个答案:

没有答案