I am using a $stateprovider
as follows from angular-ui-router in my angular application:
.state('order', {
url: "/order/:id",
templateUrl: "/myapp/order"
})
In the above scenario, we are passing an id
to the controller and we can call it as ui-sref="order({id: 1234})"
.
But now i want to make a direct call to the backend by not using a controller and pass the above as follows:
.state('order', {
url: "/order",
templateUrl: "/myapp/order/:id"
})
But obviously my syntax is wrong here. How do i achieve this scenario?
I created working example. It is adjsuting thiw Q & A:
Trying to Dynamically set a templateUrl in controller based on constant
Let's have templates
template-A.html
andtemplate-B.html
in our example. The state def withtemplateProvider
would look like thisAnd now we can call it like this
Check it here
And what's more, with latest version of angularjs we can even make it super simple:
$templateRequest
Updated plunker