angular-ui-router

check if a route exist in angular 2

*爱你&永不变心* 提交于 2019-12-10 22:16:38
问题 I want to check if a route exists in an angular project. For example user types http://localhost:4200/#/timestamp in the url bar and timestamp does not exist in the project, how will you be able to check without redirecting? 回答1: There is no way to check if the route path exists in the config, however you can do a redirect in configuration using ** in router config module. export const AppRoutes = [ { path: "", redirectTo: "home", pathMatch: "full" }, { path: '**', redirectTo: 'home'} ]; Or

Dynamic parameters with angular ui router

回眸只為那壹抹淺笑 提交于 2019-12-10 22:07:04
问题 I am wondering how to include parameters when changing state and sending the request to get the template from the backend. Here is my app: angular.module('questionnaireApp', ['ngAnimate', 'ui.router', 'ui.bootstrap']) .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { $stateProvider .state('questionnaire', { url: '/questionnaire', templateUrl: 'questionnaire/questionnaire.html', controller: 'questionnaireCtrl' }) .state('questionnaire.receiver_name

ui router resolve is throwing error provider not found

做~自己de王妃 提交于 2019-12-10 21:53:31
问题 I have got a ui -router state here var AccountParentState = { url: "/Account", views: accountrootview, stickA: true, }, AccountAddState = { url: "/add", views: addaccountview, controller: "account-controller", resolve: { Name: function () { return "Joydeep"; } } }; $stateProvider .state('account', AccountParentState) .state("account.add", AccountAddState) And this is my controller : angular.module('ngApp').controller('account-controller', ['$scope', '$state', "account", "plugin-factory",

Reuse `ui-route` controller that expects a `resolve`d parameter

拈花ヽ惹草 提交于 2019-12-10 21:37:30
问题 I want to be able to reuse my ui-router -wired controllers. They currently receive parameters from ui-router resolve to render their templates. Can I reuse those controllers without ui-router ? For example, I do this with ui-router : .controller('DetailController', function ($scope, detailData) { $scope.controllerDetail = detailData + "is awesome!"; }) .config(function ($stateprovider) { $stateprovider.state('detailState', { resolve: { detailData: function () { return "John Doe"; } },

Acess parameters of parent state from child state in stateChangeStart

末鹿安然 提交于 2019-12-10 21:13:21
问题 Is there any way to get the parameters from parent state. My states look like this. $stateProvider .state('home', { url: '/home/:param1', template: '<div>home<ui-view /></div>', data: { parentdata: 'parentdata' } }) .state('home.child', { url: '/child/:param2', template: '<div>index</div>', data: { childdata: 'childdata' } }) }) I want to access the data value of parent state from child state. $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { var

How to get an instance variable from rails using angularjs and ui router?

℡╲_俬逩灬. 提交于 2019-12-10 20:43:06
问题 I'm using a template in my state router. I want to get an instance variable from my rails server, but it doesn't have it's own path, so I can't use Restangular or something like that. Also, when I try to interpolate: #{@variable} nothing happens, because I'm in a template in my ui router, and not in a rails view. So how do I get an instance variable from my rails server into angularjs in a ui-router template? EDIT: ahaa.... just pass it in like this: ng-init="variablename = 'variable'" so in

Angular url matcher - match any path starting with

China☆狼群 提交于 2019-12-10 19:36:54
问题 I use angular2+ router and I'm trying to match any path starting with /tree e.g: example.com/projects/1/repository/tree/src example.com/projects/1/repository/tree/src/app example.com/projects/1/repository/tree/src/app/core and so on. I tried this approach, but it doesn't work: https://github.com/angular-ui/ui-router/wiki/URL-Routing#regex-parameters My router config: const routes: Routes = [ { path: 'projects/:id/repository/{tree:.*}', component: FilesListComponent } Everything after tree I

Angular UI Router: abstract : true won't display page

丶灬走出姿态 提交于 2019-12-10 19:17:56
问题 I'm trying to wrap my brain around Angular UI Router with nested navigation. My app has multiple pages. I've set up the StateProvider and the basic routing from page to page works. However, I am now trying to implement a tabbed view within one of these pages. I just can't get it to work. A basic example can be seen here: http://codepen.io/anon/pen/eBLfD Specifically: 1) the content of the first tab doesn't get loaded and 2) when I set abstract to false the page that holds the tabs does get

AngularJS force app to start from specific URL

China☆狼群 提交于 2019-12-10 18:48:00
问题 I have a specific logic sequence in my app, and I want a simple way to force my app to start from the welcome page. I am using this: $urlRouterProvider.otherwise('/pages/welcome'); the problem is that otherwise just play with the unknown URLs and redirect them to the welcome , whereas I want to redirect to the welcome in all cases, even in the registered states. 回答1: Simply try location.hash = '#/'; like the following: angular.module('app', []).config(function ($stateProvider,

Angular ui-state with params type in typescript

余生长醉 提交于 2019-12-10 18:47:48
问题 What I know When using TypeScript with angular's ui state, I can provide "type assertion" with the UI-Router definitely typed library. Using this, I can inject $state and have code similar to the following function myCtrl($state: ng.ui.IStateService){ // Some code } This gives me correct autocompletion/error reporting for $state 's methods. So far, this is all fine. The problem When I try to access a property of params like the following function myCtrl($state: ng.ui.IStateService){ // Trying