angular-ui-router

Matching url path with regex in $urlRouterProvider.when()

两盒软妹~` 提交于 2020-01-01 06:53:08
问题 Based on the angular ui-router wiki (https://github.com/angular-ui/ui-router/wiki/URL-Routing#urlrouterprovider) it should be possible to use regex for matching the incoming path. How could I express regex to match following redirection rules: $urlRouterProvider .when('', '/events') .when('/', '/events') .when('/:eventName', '/events/:eventName') .when('/results', '/events/results') Test example: localhost => localhost/#/events localhost/ => localhost/#/events localhost/myEvent => localhost/#

How do I preform a redirect in an angular interceptor

六月ゝ 毕业季﹏ 提交于 2020-01-01 05:36:08
问题 Hi guys I am pretty new to angular, and I had a question on the best way to handle a redirect within an interceptor. I have certain pages in my app that I should only be able to access if I have an account selected. So if an account is not selected I want the route the user to page to select the account. The following is my failed attempt: // within config $httpProvider.interceptors.push(function($q, $injector){ return { 'request': function(config) { var state = $injector.get('$state'); if

ui-router: default route based on user role

倾然丶 夕夏残阳落幕 提交于 2020-01-01 03:17:07
问题 I'm using UI router in my project. The home page of my application consists of 4 tabs, each routing to a different template. This is my current routing code, im using a forEach to create 6 routes. ['Draft','Assigned','InProgress','Completed','Rejected','All'].forEach(function (val) { $stateProvider.state({ name: 'root.jobs.list.' + val.toLowerCase(), url: '/' + val.toLowerCase(), views: { 'currentTab': { templateUrl: 'adminworkspace/jobs', controller: 'JobsController' } }, data: {

Prevent a stateChange with angular ui router without using $rootScope

北城以北 提交于 2019-12-31 08:34:15
问题 My user can leave a state but before I want to show a modal dialog "Do you want to save?" ONLY if the user data is dirty that means changed. What I do NOT want is to stick a isDirty property in my EditController to the $rootScope go to the stateChangeStart event and check there for isDirty and then show/not the save dialog. Prevent global variables says every javascript beginner book... 1.) What is then the pro way to prevent a state change without hacking the $rootscope?. 2.) Are there any

ui-router: async data in templateUrl function

删除回忆录丶 提交于 2019-12-31 05:57:37
问题 I've run into quite a novel problem with ui router. I'm basically trying to query my API for a template url, which is stored and returned as a Resource object. The problem, is it seems that the templateUrl function is returning as undefined. My code is as follows: (function() { 'use strict'; angular.module('myApp') .config(function ($stateProvider, PageProvider, $httpProvider) { $stateProvider .state('core', { abstract: true, templateUrl: 'app/core/core.index.html', controller:

ui-router: async data in templateUrl function

此生再无相见时 提交于 2019-12-31 05:56:50
问题 I've run into quite a novel problem with ui router. I'm basically trying to query my API for a template url, which is stored and returned as a Resource object. The problem, is it seems that the templateUrl function is returning as undefined. My code is as follows: (function() { 'use strict'; angular.module('myApp') .config(function ($stateProvider, PageProvider, $httpProvider) { $stateProvider .state('core', { abstract: true, templateUrl: 'app/core/core.index.html', controller:

Passing data from one route view to another

别等时光非礼了梦想. 提交于 2019-12-31 04:09:06
问题 I want to pass some values from one view to another in Angularjs using ui-Router. I don't want to use $rootScope to save data or create a new services ( as I have many views that pass small bits of data so creating new jsfile for few lines code is not fun). A super-minified example of what I want to do is: Controller of View 1 $scope.goodFood = 10 $scope.badFood = 2 Controller of View 2 $scope.results = 10 - 2 (from view 1's scope) Is there any quick way to do these kinds of small operations

Angular UI Router issue when redirecting to a template after resolve() throws error

99封情书 提交于 2019-12-31 02:23:09
问题 So It took me a very long time to understand this issue and get to a mcve. Here is the case : I'm trying to redirect a user to a login page when he's not authenticated (this is very basic). Here is the code : HTML : <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.13/angular-ui-router.min.js"></script> <script src="js/app.js"></script> </head> <body ng-app=

Angular UI Router issue when redirecting to a template after resolve() throws error

折月煮酒 提交于 2019-12-31 02:23:05
问题 So It took me a very long time to understand this issue and get to a mcve. Here is the case : I'm trying to redirect a user to a login page when he's not authenticated (this is very basic). Here is the code : HTML : <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.13/angular-ui-router.min.js"></script> <script src="js/app.js"></script> </head> <body ng-app=

Angular ui-router cannot resolve $resource results

微笑、不失礼 提交于 2019-12-31 02:14:10
问题 In one of my UI-router states, I have the following link '/users' , which points to a page that shows a list of users. Below is the code I wrote to resolve the list of users by using a $resource call, however, the data doesn't seem resolved when the page is loaded: .state('users', { url: '/users', templateUrl: '/assets/angularApp/partials/users.html', controller: 'UserListCtrl as vm', resolve: { users: function ($resource) { return $resource('http://localhost:8080/api/users').query().$promise