How to insert $ httpParamSerializer for use in templateUrl

I am trying to enter $httpParamSerializerfor use in templateUrl, but I am having some problems. There is no good documentation or usage examples $httpParamSerializer.

Code example:

angular.module('myApp', ['ngRoute']).config(
  function($routeProvider, $locationProvider, $httpProvider) {
    $routeProvider
        .when('/data/dashboard', {
            templateUrl: function(params) {
             //NEED TO USE IT HERE
            }
        })
})

Things that didn't work out by putting them like this:

function($routeProvider, $locationProvider, $httpProvider,$httpParamSerializer ) {

Also in the module, for example:

angular.module('myApp', ['ngRoute', '$httpParamSerializer']).config(

Any understanding of why this is not working will help.

+4
source share
2 answers

Since you are in the config, you need to get it from the provider itself. That is, enter the provider and call$get

angular.module('myApp', ['ngRoute']).config(
  function($routeProvider, $locationProvider, $httpProvider, $httpParamSerializerProvider) {

    // get the serializer from the provider
    var paramSerializer = $httpParamSerializerProvider.$get();
    console.log(paramSerializer({a:1})); // test it

    $routeProvider.when('/', {
      templateUrl: function(params) {
        // you can use paramSerializer(here
      }
  });
});

The working version of your jsfiddle is: http://jsfiddle.net/kh9oeq1y/16/

+3
source

angular. , 1.4.0.

-1

All Articles