r/angularjs • • Mar 27 '16

UI-Router 1.0.0-alpha.1 released.

https://github.com/angular-ui/ui-router/releases/tag/1.0.0-alpha.1
51 Upvotes

7 comments sorted by

3

u/ctanga Mar 27 '16 edited Mar 28 '16

1.0.0-alpha.1 (2016-03-27)

This release checkpoints the continued development of the 1.0 codebase, as we approach final release.

Notable additions in this release:

Packages

We are now publishing three separate packages using a new publishing architecture:

  • ui-router-core (npm) framework agnostic core

  • angular-ui-router (npm and bower) angular 1

  • ui-router-ng2 (npm; coming soon!) angular 2

The ui-router-core package is framework-agnostic. Both ng1 and ng2 packages share the code in ui-router-core and provide viewport adapters to implement the <ui-view>. Third parties could potentially depend on ui-router-core to implement ui-router adapter for any other framework.

Route to component

We now support routing to angular 1.5+ .component()s in two different ways. We now put the resolved data on $scope.$resolve (or $scope[controllerAs]$resolve), so you can use Components as route templates in the same way as ngRoute.

We also now allow a state's view to be specified using component: 'MyComponent' in lieu of a controller+template. We will map resolve data to the component's bindings: by name.

See the component and bindings for more information.

We also support angular 1.3+ .component() with Todd Motto's polyfill, and even support old school angular 1.2 directives (instead of bindings: { foo: '<' }, we will map to scope: { foo: '=' }).

View hooks (component/controller hooks)

For a long time, we've advocated using the state machine to manage application lifecycle. However, using callbacks such as onExit can be challenging, since the answer to "can I exit this state?" often lives in the view. We've introduced some view-level callbacks that can be used to integrate controller code with the transition pipeline.

The first view hook we've implemented is uiCanExit(). This hook can be used much the same as the component router's routerCanDeactivate. See the Ng1Controller docs for more information. The uiCanExit view hook is simply sugar for adding a transition onBefore hook.

Dynamic params

Dynamic parameters (the replacement for reloadOnSearch) can be declared in a params block in a state definition like so: params; { fooParam: { dynamic: true } }. When a dynamic parameter changes, it does not cause the state to be reloaded. A controller/component callback uiOnParamsChanged may be used to be notified of parameter changes.

See the Ng1Controller docs for details on the new callback.

Expose internal state object's API

We're now exposing the internal state objects via an undocumented API. This can be useful for other library authors who need access to things like .parent or .includes. This internal API is subject to change (it hasn't changed much so far), so be careful. The internal api of an arbitrary state can be fetched like so:

var normalState = $state.get('foo'); 
var internalStateObject = normalState.$$state();  
console.log(internalStateObject.parent.name);

We will maintain a list of Known BC from 0.2.x to 1.0 final to help you upgrade to the 1.0 release.

5

u/jax024 Mar 28 '16

This is a huge boost to angular 1.5. This actually makes it almost as sexy as ng2 with good principles now. I love it.

1

u/mrc1897 Mar 28 '16

Working on a ~4 month old application with Angular 1.5.x. I would like to upgrade from UI Router 0.2.15 to 1.0.0A but a bit concerned that this is ... well alpha. The app hasn't launched yet so I could do the upgrade without breaking production code but I'm not sure about bringing an alpha release into an app that will see release soon. Any thoughts?

2

u/ctanga Mar 29 '16

it's probably fine ¯_(ツ)_/¯

If not, let me know whats broke

2

u/Xerxero Mar 28 '16

Finally. We are using 1.5 components and getting the resolve to work was kinda awkward.

-1

u/inknownis Mar 28 '16

I am new to angular' component. How much different between components and states? Seems to me they are going to be co-existing. To me, ui-route is simpler and better. This only applies to 1.x as I have not studied 2.

2

u/ctanga Mar 28 '16

A component is basically a template and a controller encapsulated as a single concept, with well-defined inputs (and outputs).

In ui-router, a state generally has one or more views. The component is the view.