In a controller in Angular Js, I want to learn if html5Mode is enabled, or not. How can I do that?
In config phase I can set $locationProvider.html5Mode(true)
or I can learn html5Mode is enabled or not by using $locationProvider.html5Mode()
However, I can't do the same on a "run" block, like this:
var isHtml5enabled = $location.html5mode() // looking for something like this...
Is there a way to do this?
Why I need it?
I am trying to modify ui-router.
ui-router
's ui-sref
directive and $state.href("")
service/method generates url without considering if it is in Html5Mode or not.
If Html5Mode is enabled, a url like this is ok: /my/base/path/generated/by/uirouter
But if it's disabled, it should be like this: /my/base/path/#/generated/by/uirouter
So I'm trying to detect status of Html5Mode.
I did it on config phase, but another module can change status of it after I read the information. (I guess...) That is why I want to determine status of Html5Mode on a controller/run block.
Although it's late but I find that you can detect whether HTML5 mode is on by $location.$$html5
. So you can do this in your controller:
if (!$location.$$html5) {
// your code to execute when HTML5 mode is not enabled
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With