1. <i id='vXQ7w'><tr id='vXQ7w'><dt id='vXQ7w'><q id='vXQ7w'><span id='vXQ7w'><b id='vXQ7w'><form id='vXQ7w'><ins id='vXQ7w'></ins><ul id='vXQ7w'></ul><sub id='vXQ7w'></sub></form><legend id='vXQ7w'></legend><bdo id='vXQ7w'><pre id='vXQ7w'><center id='vXQ7w'></center></pre></bdo></b><th id='vXQ7w'></th></span></q></dt></tr></i><div id='vXQ7w'><tfoot id='vXQ7w'></tfoot><dl id='vXQ7w'><fieldset id='vXQ7w'></fieldset></dl></div>
      <legend id='vXQ7w'><style id='vXQ7w'><dir id='vXQ7w'><q id='vXQ7w'></q></dir></style></legend>

        <bdo id='vXQ7w'></bdo><ul id='vXQ7w'></ul>

      <small id='vXQ7w'></small><noframes id='vXQ7w'>

    2. <tfoot id='vXQ7w'></tfoot>

      如何将 $stateParams 从 ui-router 传递给解析服务?

      How to pass $stateParams from ui-router to service in resolve?(如何将 $stateParams 从 ui-router 传递给解析服务?)
      <tfoot id='0laGG'></tfoot>

    3. <small id='0laGG'></small><noframes id='0laGG'>

        <bdo id='0laGG'></bdo><ul id='0laGG'></ul>

              <tbody id='0laGG'></tbody>
            <legend id='0laGG'><style id='0laGG'><dir id='0laGG'><q id='0laGG'></q></dir></style></legend>
              <i id='0laGG'><tr id='0laGG'><dt id='0laGG'><q id='0laGG'><span id='0laGG'><b id='0laGG'><form id='0laGG'><ins id='0laGG'></ins><ul id='0laGG'></ul><sub id='0laGG'></sub></form><legend id='0laGG'></legend><bdo id='0laGG'><pre id='0laGG'><center id='0laGG'></center></pre></bdo></b><th id='0laGG'></th></span></q></dt></tr></i><div id='0laGG'><tfoot id='0laGG'></tfoot><dl id='0laGG'><fieldset id='0laGG'></fieldset></dl></div>
              • 本文介绍了如何将 $stateParams 从 ui-router 传递给解析服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个检索单个帖子的路由和一个查询我的 API 的服务.但是我需要将参数从 URL 传递给服务,以便我可以正确调用 API.我不知道该怎么做.

                I have a route to retrieve a single post and a service to query my API to do so. But I need to pass parameters from the URL to the service so that I can call the API properly. I cannot wrap my head around how to do that.

                这是我到目前为止所想出的.我省略了似乎与这个问题无关的内容.

                This is what I have come up with so far. I left out what seemed not relevant for this question.

                感谢您的帮助!

                路由

                myModule.config([
                  '$stateProvider',
                  '$urlRouterProvider',
                  '$locationProvider',
                  function($stateProvider, $urlRouterProvider, $locationProvider) {
                
                    $stateProvider
                      .state('post', {
                        url: '/posts/:hash_id/:slug',
                        templateUrl: '/js/app/views/post.html',
                        controller: 'PostCtrl',
                        resolve: {
                          postPromise: ['posts', function(posts, $stateParams){
                            //returns undefined
                            console.log($stateParams);
                            return posts.getOne($stateParams);
                          }]
                        }
                      })
                // etc
                

                服务

                myModule.factory('posts', ['$http', 'auth', function($http, auth){
                  var o = {
                    posts: [],
                    post: {}
                  };
                  o.getOne = function(params) {
                    // Returns undefined
                    console.log(params);
                    return $http.get('/api/v1/posts/' + params.hash_id).success(function(data){
                      angular.copy(data, o.post);
                    });
                  };
                  return o;
                }])
                

                推荐答案

                你错过了在 postPromise resolve

                You missed to add $stateParams dependency in postPromise resolve

                代码

                postPromise: ['posts', '$stateParams', function(posts, $stateParams){
                

                这篇关于如何将 $stateParams 从 ui-router 传递给解析服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                JavaScript radio button confirmation(JavaScript 单选按钮确认)
                How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                AngularJs. Is it possible to deselect HTML “radio” input by click?(AngularJs.是否可以通过单击取消选择 HTML“收音机输入?)
                Checking Value of Radio Button Group via JavaScript?(通过 JavaScript 检查单选按钮组的值?)
                    <tfoot id='wCXGx'></tfoot>
                      <tbody id='wCXGx'></tbody>

                      <legend id='wCXGx'><style id='wCXGx'><dir id='wCXGx'><q id='wCXGx'></q></dir></style></legend>
                      • <small id='wCXGx'></small><noframes id='wCXGx'>

                      • <i id='wCXGx'><tr id='wCXGx'><dt id='wCXGx'><q id='wCXGx'><span id='wCXGx'><b id='wCXGx'><form id='wCXGx'><ins id='wCXGx'></ins><ul id='wCXGx'></ul><sub id='wCXGx'></sub></form><legend id='wCXGx'></legend><bdo id='wCXGx'><pre id='wCXGx'><center id='wCXGx'></center></pre></bdo></b><th id='wCXGx'></th></span></q></dt></tr></i><div id='wCXGx'><tfoot id='wCXGx'></tfoot><dl id='wCXGx'><fieldset id='wCXGx'></fieldset></dl></div>

                          <bdo id='wCXGx'></bdo><ul id='wCXGx'></ul>