I am currently trying to set up a table to go to a profile page when you click a row. But $location.url will simply append the 'profile.html' to the end of the current html page and not take me to the profile page. How do I change the current url to allow me to go to my page.
index html:
http://localhost:9080/AgentOnlineApp/index.html
html I get when I click the row:
http://localhost:9080/AgentOnlineApp/index.html#/profile.html
I want:
http://localhost:9080/AgentOnlineApp/profile.html
current AngularJS code:
$scope.selectTableRow = function(agent)
{
$location.url('/profile.html');
}
You might want to try this to load another page (outside your application):
$window.location.replace("profile.html")
Don't forget to inject $window
If you want to use the HTML5 history API, you need to set:
$locationProvider.html5Mode(true);
If you actually want to change the location entirely and reload the page, you are not quite using Angular as intended since this wouldn't be a single page app. However, you could do it with window.location = "profile.html"
Related
I have home page that lists items, but also when I add an item I want to popToRoot(), to home page. Now, If I come to root from addItemPage, I want to show the button to save a list, to make a HTTP call..
Is it possible, I was thinking about passing the for example (fromAdd: true) to navCtrl and then based on that show the button(ngIf) ?
You can use any of the rootscope variables, navparams and service to set the value on the parent page and then access it in your ng-init function declared on you child page and show your button on the basis of that value by using ngIf expression.
I am consuming a web service before navigating to a controller. and here I GET a web request and the result of this request I keep it in the variable $rootScope.userSesion .This web service I want to run it every time I navigate to another view so I do not have to put the same code on each controller. :
angularRoutingApp.run(function($rootScope, $http){
// this code is executed every time I change the view
$transitions.onStart({ }, trans => {
.
.
.
$rootScope.userSesion="gestionarUsuarios";
})
.
.
.
})
in the html view I'm putting my $rootScope.userSesion variable. when inspecting the element to which I want to click and that sends me to the state that I put in the ui-sref, does nothing and redirects me to another state('gestionarUsuarios'). the href tag attribute corresponds to the url of my current view.
when I click I should go to the "manageUsers" state but nothing happens. This is the code of my view.
<a class="columna_menu border_contenedor_seis" ui-sref="{{userSesion.estado}}">
<div class="welle welle_seis"></div>
I want it when I click on the element to which I change the *ui-sref** allow me to navigate normally.
It is hard to debug this issue from 3 lines of code, but as variable userSesion is a type string, your ui-sref should look like ui-sref="{{ userSesion }}.estado"
Using UI-Router v1.0rc1, is it possible to transition to the current state, changing only one param, without reloading the state. Let me give you my use case:
On the left of the page I show the listings titles of a user. When clicking on a title the main content is changed to... the listing data obviously. When clicking on another title, the current 'listing' state is reloaded and fed with other data. In my listing template, I have a map. Each time a new listing must be displayed, the dom is destroyed and reloaded (with the same template) which kills the map and rebuilds it. I would prefer to only change the params (the listing id) of the listing state, detect it and change the content of the template (and reposition the map). The actual listing data is currently loaded in the resolves thanks to the id param.
Is it something feasible?
Try this:
$state.go('some.state', { param: 'x' }, {reload: false});
more about reload can be found here
I have a page with items that each item has an ID.
When selecting an item, I'm changing the URL using angular $location.search to look something like this:
http://domain/all-items//?id=55f57cbe5e49356039839d32
I'm doing it so users will be able to copy this URL and send it to their colleagues.
When navigating to this kind of URL, it shows the correct item.
The problem happens when refreshing the page.
When I'm refreshing, I don't want the page to select the unique item, I want it to show all items, that's why I need the URL to be:
http://domain/all-items//
or even:
http://domain/all-items//?id=
before refreshing the page.
I tried to do it using angular's:
$window.onbeforeunload = function (e) {
$location.search('id', '');
};
(also with $location.search('id', null) )
But it doesn't do anything.
All I found while searching for answers is how to change the URL without refreshing the page, what I need is how to change the URL before refreshing the page.
The documentation alludes to using null
$location.search('id', null);
In my user controller,i use a outlet to render userLog section,and use controllerFor('userLog').set('model',App.UserLog.find(model.id)) to set the model of userLog,but i want to add a button to userLog section ,when user click it,it will load more logs,but i tried to push new object to its model,nothing happened.
here is the project address:https://bitbucket.org/magicshui/web/src/4ff895b5c22823c6ec1c1536ca2e7b59237f0459/assets/coffee/app/routes/?at=master
when you goto web/index.html#/users and then click one user name,it will show the section,because i haven't set all url correctly,so you should fill into the address bar this address directly.
the problem file is user.coffee and userLog.coffee
thanks for your help
you should be using pushObject instead of push that's how Ember catches that you've changed the array and updates the template