Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantage of angular UIRouter over ng-include?

I'm wondering whether to use angular UI router or just use simple ng-include, i'm failing to fully understand why would i pick to include entire library over the built-in ng-include which gives me about the same functionality with less code?

Can someone explain whats wrong with

<div ng-if="somestate" ng-include="someview"></div> 
like image 463
cmvr Avatar asked Sep 29 '22 20:09

cmvr


1 Answers

Can someone explain whats wrong with

<div ng-if="somestate" ng-include="someview"></div> 

It doesn't handle URLs in any way. You want the URL to change when you go to another state, and you want the state to change when the URL changes. You want to be able to bookmark a page in your app, or send its URL by email, and come back to this page rather than the home page when opening the bookmark or the link.

It also doesn't allow resolving data before switching to a state.Both ui-router and ngRoute allow doing that: the state changes only when the data needed to display this state has been successfully loaded.

That's the main job of ui-router and ngRoute. ui-router has many other goodies, like events when changing state, named views, state inheritance (very useful to handle a view consisting of several tabs, for example), etc.

like image 182
JB Nizet Avatar answered Oct 20 '22 08:10

JB Nizet