SoftTimur SoftTimur - 30 days ago 11
AngularJS Question

Make $location.path open in the same frame (target = "_self")

In a mean-stack web application with html5mode, I have defined the following angular-ui-router

.state('addinHome', {
url: '/addin/home',
template: "home page"
})


Then, I have another page
https://localhost:3000/test/
with a button
<a href="/addin/home">button</a>
. Also in its controller, I have

... ...
$location.path("/addin/home")
... ...


Normally, both
$location.path
and the button lead to
https://localhost:3000/addin/home
.

Now, I add the following references in
index.html
:

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script src="https://cdn.rawgit.com/devote/HTML5-History-API/master/history.js"></script>


It disturbs the ui-router. As a consequence, both
$location.path
and the button lead to
https://localhost:3000/test/#%2Faddin#%2Fhome
, which is NOT what I want.

I have found the solution to fix the button: it is using
<a href="addin/home" target="_self">button</a>
(opens the linked document in the same frame as it was clicked; see here).

However, I have not found the solution to fix
$location.path("/addin/home")
. Could anyone help?

Answer Source
  • Inject $window as dependency.

  • Try using $window.open(URL,"_self")