Phillip Chan Phillip Chan - 1 year ago 68
AngularJS Question

AngularJS - How to Get TemplateUrl from Controller?

I'm trying to access the current template URL when I change states in the template's controller.

The routes:

function($stateProvider, $urlRouterProvider, $locationProvider, stringUtilsProvider) {
templateUrl: function($stateParams) {
return 'src/pages/' + $stateParams.doc + '.html';
url: '/docs/:doc'

In the controller, I'd like to know what the templateURL actually returns:

function($scope, $location, $state) {
// how to get current url of template?

As in, if the templateURL returned
how would i get that url from the controller?

I've looked at a number of SO answers suggesting accessing
, or
in the controller but I still cannot get it.

Answer Source

Have you tried this yet?


Otherwise do a console.log($state.current) and see if you can find your data there.


I just tested it and it works, but note the capital 'U' in 'Url', so like this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download