I am seeking guidance on loading a template for a specific state in Angular using $http
after coming across this question on Stack Overflow: Is it possible to load a template via AJAX request for UI-Router in Angular?
The documentation for ui.router demonstrates the use of both $timeout
and $http
within the configuration of $stateProvider
. However, I have realized that these services are not accessible during the module's config phase when configuring $stateProvider
, as demonstrated in the provided example.
Or you can use a template provider function which can be injected, has access to locals, and must return template HTML, like this:
$stateProvider.state('contacts', { templateProvider: function
($timeout, $stateParams) {
return $timeout(function () {
return '<h1>' + $stateParams.contactId + '</h1>'
}, 100);
}
})
As per the documentation, is there a way to access either $timeout
or $http
when configuring $stateProvider
? Should state configuration take place at another stage? Are there alternative methods for achieving this that I may have overlooked?