Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining wheter HTML5 mode is enabled in a controller

In a controller in Angular Js, I want to learn if html5Mode is enabled, or not. How can I do that?

Details:

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?

Update

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.

like image 305
Umut Benzer Avatar asked Jul 22 '13 16:07

Umut Benzer


1 Answers

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
}
like image 196
tjfdfs Avatar answered Sep 28 '22 06:09

tjfdfs