On Github nateabele / ui-router-talk
Hypermedia APIs + front-end architectures with AngularJS
$stateProvider.state("myState", { controller: "MyStateController", templateUrl: "/templates/my-state.html", // or views: { ... } /* ... */ });
$stateProvider.state("myState", { /* ... */ onEnter: function($stateParams, MyService) { /* ... */ } onExit: function($stateParams, MyService) { /* ... */ }, resolve: { dynamicData: function($stateParams, OtherService) { return OtherService.loadAThing(); // promise } } });
$urlMatcherFactoryProvider.type("Location", { encode: function (loc) { return "@" + [loc.lat, loc.lon, loc.zoom].join(",") + "z"; }, decode: function (string) { var val = this.pattern.exec(string); return { lat: val[1], lon: val[2], zoom: val[3] }; }, pattern: /imagination-here/ });
$stateProvider.state("map", { url: "/map/{location:Location}", params: { location: { dynamic: true } } });
function MapController($scope, $stateParams) { // Expose for binding to maps directive $scope.location = $stateParams.location; // Changes to map will auto-propagate to URL }