user2938828
user2938828

Reputation: 91

templateURL function not getting evaluated correctly

I have a route provider defined:

$routeProvider.when('/interview', {
    controller: 'Interview',
    templateUrl: function(parms) {
    return parms.target + '/partials/Interview.html';
    }
});

But I get the following exception:

Uncaught TypeError: Object function (parms) {
                   return 'partials/Interview.html';
                } has no method 'match'

With breakpoints, I found that AngularJS thinks my function is an URL.

Completely confused.

Upvotes: 1

Views: 983

Answers (1)

John Ledbetter
John Ledbetter

Reputation: 14203

You're probably using an the stable version (1.0.8) of angular which doesn't allow for templateUrl to be a function. You should give it a shot with the latest release candidate, 1.2-rc3.

1.0.8 documentation for $routeProvider:

templateUrl – {string=} – path to an html template that should be used by ngView.

1.2-rc3 documentation for $routeProvider:

templateUrl – {string=|function()=} – path or function that returns a path to an html template that should be used by ngView.

If templateUrl is a function, it will be called with the following parameters:

{Array.} - route parameters extracted from the current $location.path() by applying the current route

Upvotes: 1

Related Questions