Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameters for states without URLs in ui-router for AngularJS

I am using ui-router to represent states in my AngularJS app. In it I'd like to change the state without changing the URL (basically a "detail view" is updated but this should not affect the URL).

I use <a ui-sref="item.detail({id: item.id})"> to display the detail but this only works if I specify a URL like url: "/detail-:id" in my $stateProvider.

It seems to me that the current state is only defined through the URL.

like image 261
akirk Avatar asked Apr 02 '14 14:04

akirk


People also ask

What is the use of $state in AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.

What is UI-Router in AngularJS?

Angular-UI-Router is an AngularJS module used to create routes for AngularJS applications. Routes are an important part of Single-Page-Applications (SPAs) as well as regular applications and Angular-UI-Router provides easy creation and usage of routes in AngularJS.

What is UI-sref in AngularJS?

ui-sref stands for UI-Router state reference. It's a way to change states/state params (as defined in using the $stateProvider in a config block using the ui. router module for AngularJS. You can read the ui-sref documentation here.

What is UI route?

UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).


1 Answers

Just an additional information for new comers to this post:

Declaration of params in a state definition has changed to params: { id: {} } from params: ['id']

So be aware :)

Source: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider

like image 77
gulsahkandemir Avatar answered Sep 22 '22 02:09

gulsahkandemir