Reputation: 2119
Is it possible to use templateUrl instead of the embedded template in ui-router? If yes, which approach is better?
Upvotes: 0
Views: 254
Reputation: 1304
Yes, you can use templateUrl in ui-router.
.state('stateName', {
templateUrl: 'path/to/template',
controller: 'someController'
});
But which is the best approach is a trick question. Its all about how you are going to use the state. For example,
template
;.state('stateName', {
template: '<component-name></component-name>'
});
This is one of the most common approch for component. If you using ui-router version above 1.5, then you can do following too,
.state('stateName', {
component: 'component-name'
})
.state('stateName', {
templateUrl: 'path/to/template',
controller: 'someController'
})
But directly writing the html like below is considered as bad practice
.state('stateName', {
templateUrl: '<div><p>never do this</p></div>',
controller: 'someController'
});
Upvotes: 1