6footunder
6footunder

Reputation: 1358

How to validate state with angular ui-router

We're using angular-ui-router (version 0.2.10 i believe).

There are two primary ways to arrive at a state,

We would like in case a) to validate the state (e.g. is it valid according to one or more business rules), but not to do so in case b) since we're pretty sure that our application will only transition to valid states.

Case a) will often require an http round trip to perform validation which we'd like to avoid if possible.

How would this be implemented?

Thanks!

Upvotes: 5

Views: 1697

Answers (1)

lex82
lex82

Reputation: 11317

You could wrap the validation in a service and call it every time the state changes. However, before moving to another state with $state.go(), you instruct the validation service to consider the particular parameters you are passing as valid. E.g.

validationService.trustAsValid(yourData);

Upvotes: 0

Related Questions