angular-ui-router

How to keep globally current user until logout with angular_devise?

删除回忆录丶 提交于 2019-12-12 08:18:33
问题 How to create own service accessible globally that will call server by currentUser() only once on page load, if User is logged in then keep it and provide data to controllers or states until logout? Now I'm resolving many times in many states or controllers currentUser() , I found in docs: authparseresponse that it is possibility to make own service, but I don't know how to handle this in right way. e.g in ui-router I've two server calls, would be sufficient only when page is loaded: .state(

Calling an angularjs ui-router state from within a controller

隐身守侯 提交于 2019-12-12 08:15:56
问题 I use the angularjs ui-router to establish the various states within an app. While I know I can go to the state from a link in the html (via ui-sref ), is it possible to go to the state from within a controller? The code snippets below are a simple angularjs app to help illustrate my point. In the example below, I have two states: There is a state called home that is a simple form containing a text input field and a button that calls a search function in the controller. There is a state

AngularJS ui-router otherwise to state instead of url?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 07:48:08
问题 I am using AngularJS and ui-router and in my app.js . I have the following line: $urlRouterProvider.otherwise('/'); However I do not want it to send the user to a URL but instead to a state : .state('404', { views: { 'body': { templateUrl: 'partials/404.html', } } }); Normally I would just do this: $state.go('404'); How can I do this for the otherwise method? Note: that my 404 state does not have a URL, so basically it keeps the URL that the user has entered or visited and just changes the

Prevent routing in Angular when user manually changes url in browser tab

主宰稳场 提交于 2019-12-12 07:27:09
问题 I am stuck in a issue that happens when user manually changes the route in browser tab and presses enter. This forces my ui-router/angular2-router to navigate to the state entered by user. I want to prevent this and allow routing only through the flow I have implemented by button clicks in my website. 回答1: Its 2018! Angular 5 is here and so is the solution to this issue. BAMM its CanActivate Interface that a class can implement to be a guard deciding if a route can be activated. We can add

Angular UI-router and using dynamic templates

ぃ、小莉子 提交于 2019-12-12 07:22:20
问题 I'm trying to load a template file using a rootscope value as for it's name. I have a init controller which sets the $rootScope.template to "whatever.html", then I have my route like this: $stateProvider.state('/', { url: '/', access: 'public', views: { page: { controller: 'HomeCtrl', templateProvider: function($templateFactory, $rootScope) { return $templateFactory.fromUrl('/templates/' + $rootScope.template); } } } }); But this doesn't work. It actually freezes the whole chrome so that I

Can you use ng-click with ui-sref?

丶灬走出姿态 提交于 2019-12-12 07:17:03
问题 Can I do this? <button ng-click='vm.foo()' ui-sref='state'>test</button> 回答1: Yes. ngClick will run, and then you'll transition to your state. Demo (updated and working thanks to marioosh) However, if you have an $event.preventDefault() in ngClick , it won't transition you to your state. Full code example <!DOCTYPE html> <html ng-app='app'> <head> <script data-require="angular.js@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script> <script data-require="ui

Routing does not work well with HTML5-History-API

一世执手 提交于 2019-12-12 06:48:14
问题 In a mean-stack web application, I use html5mode and have the following code in index.html : <base href="/" /> <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script> <script src="https://cdn.rawgit.com/devote/HTML5-History-API/master/history.js"></script> I have defined the following angular-ui-router: .state('addinHome', { url: '/addin/home', template: "home page" }) .state('addinTest', { url: '/addin/test', template: '<a href="addin/home">one</a>', controller:

AngularJS [UI-Router] urlRouteProvider.when() versus resolve for routing to child states

拜拜、爱过 提交于 2019-12-12 06:45:40
问题 In my app I have a state called 'dashboard' with multiple child states .state('dashboard', { url: '/dashboard', abstract: true, // resolve async objects before controller instantiation. resolve: { productResolve: function ($state, authService, cacheService, productService) { var cache = cacheService.getCache(); if (cache.length === 0){ return productService.getProductsAndCommoditiesAsync(authService.getCredentials().roleID) .then(function(productData){ cacheService.setCache(productData); },

Get URL param in Express API from Angular UI-Router

允我心安 提交于 2019-12-12 06:24:47
问题 I can't get the param of the URL which I pass when changing the state in Angular (ui router): .state('contact.detail', { url: '/:contactId', templateUrl: 'detail.html', controller: 'DetailController' }) In Express I define an API, but the problem is in getting the param from the URL which I passed from ui router (above). server.js var express = require('express'); var mysql = require('mysql'); var url = require('url'); var app = express(); app.use('/', express.static('../app')); app.use('

$update PUT method in Angular?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 06:14:52
问题 I couldn't find any examples of using an $update PUT method in Angular when using ui-router instead of ngRoute for routing. Is an $update PUT method possible when using ui-router? 回答1: The $update method in the example you linked in the question comments has nothing to do with $routeParams or $stateParams . Those (in most cases) just refer the parameters that are present within the url. As an example, if you declared a url in your config as: /#/foo/:id/bar and you visited the url: /#/foo/5