1

httpインターセプターを使用しています。Restangular GET リクエストを行うと、すべての値が表示されます。これが私のリクエストインターセプターのコードです。

request: function (config) {
    // see link below to see value of config
    console.log('config', config);

    // below returns full url except query string
    console.log('location', $location.absUrl());

    // $rootScope.cacheData is $cacheFactory
    console.log('$rootScope', $rootScope.cacheData);

    // only returns {id: "http", size: 3}
    console.log('cache info', $rootScope.cacheData.info());

    // below returns undefined
    console.log('cache get', $rootScope.cacheData.get('http'));

    // other codes removed since it's not related
    // ........
    // ........
    // Return the config or wrap it in a promise if blank.
    return config || $q.when(config);
},

設定値: http://i.imgur.com/l0IsXbJ.png

残念ながら、手動で取得したパラメーターを準備しても、キャッシュされたものと一致することが 100% 保証されるわけではありません。私は、cacheFactory が要求された正確な文字列をチェックしていることに気付きました。したがって、GET リクエストのクエリ パラメータが age=12&name=scott である場合、http インターセプターでは、最初に name を入力し、次に age(name=scott&age=12) という逆の方法で準備します。cacheFactory はそれを見つけられません。

そのため、私たちが行ったリクエストと同じ完全な URL を返す角度付きサービスまたはファクトリを探しています。$location を試しましたが、完全な GET リクエストが返されません。

4

1 に答える 1