angularjs-routing

AngularJS | handle routing before they load

十年热恋 提交于 2019-12-17 17:29:31
问题 I wish to create a simple authentication check for my routes by external service. I define the access requirements on the route object: $routeProvider .when('/', { templateUrl: 'src/app/views/index.html', controller: 'indexCtrl', authenticated: true }) .when('/login', { templateUrl: 'src/app/views/login.html', controller: 'loginCtrl', anonymous: true }) .otherwise({ redirectTo: '/' }) ; Then, I check if I have permission within the $routeChangeStart event. $rootScope.$on('$routeChangeStart',

Do angular views work when a site is served from the local file system?

假如想象 提交于 2019-12-17 16:59:25
问题 I'm using angular to develop an application. I'm developing off my local file system, on Windows. However, when I enable angular-route.js , whenever I hit index.html with my browser, it instead goes to index.html#/C:/ . My route definition is: myApp.config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', {templateUrl: 'home.html', controller: 'HomeCtrl'}); } I think this causes the site to break, because /C:/ doesn't match any angular routes. What's going wrong? How do I

angularjs route unit testing

ε祈祈猫儿з 提交于 2019-12-17 15:23:32
问题 As we see here in http://docs.angularjs.org/tutorial/step_07, angular.module('phonecat', []). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}). when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}). otherwise({redirectTo: '/phones'}); }]); routing test is suggested to be done with e2e test, it('should redirect index.html to index.html#/phones',

Is there a way to preload templates when using AngularJS routing?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 15:23:02
问题 After the Angular app is loaded I need some of the templates to be available offline. Something like this would be ideal: $routeProvider .when('/p1', { controller: controller1, templateUrl: 'Template1.html', preload: true }) 回答1: There is a template cache service : $templateCache which can be used to preload templates in a javascript module. For example, taken from the docs: var myApp = angular.module('myApp', []); myApp.run(function($templateCache) { $templateCache.put('templateId.html',

how to pass querystring in angular routes?

∥☆過路亽.° 提交于 2019-12-17 10:44:35
问题 I am working with AngularJS routes, and am trying to see how to work with query strings (for example, url.com?key=value ). Angular doesn't understand the route which contains key-value pair for the same name albums : angular.module('myApp', ['myApp.directives', 'myApp.services']).config( ['$routeProvider', function($routeProvider) { $routeProvider. when('/albums', {templateUrl: 'albums.html', controller: albumsCtrl}). when('/albums?:album_id', {templateUrl: 'album_images.html', controller:

AngularJS Dynamic loading a controller

风流意气都作罢 提交于 2019-12-17 10:34:51
问题 I read a lot about lazzy loading, but I am facing a problem when using $routeProvider. My goal is to load a javascript file which contains a controller and add a route to this controller which has been loaded previously. Content of my javascript file to load angular.module('demoApp.modules').controller('MouseTestCtrlA', ['$scope', function ($scope) { console.log("MouseTestCtrlA"); $scope.name = "MouseTestCtrlA"; }]); This file is not included when angular bootstap is called. It means, I have

Routing in angularjs for multiple controllers?

不问归期 提交于 2019-12-17 09:47:56
问题 I'm trying to build a view - I've set up two controllers to practice, one's HeaderCtrl, with some data in it (site title, header background, etc), the other should have the main content of the page - MainCtrl. When defining the route, I'm doing like so: mainApp.config(function ($routeProvider) { $routeProvider .when('/', { controller: 'MainCtrl', templateUrl: 'modules/dashboard.html' }) }) This works perfectly fine, but what I would want is to specify multiple parameters to this, something

scope and controller instantiation with ui router

可紊 提交于 2019-12-17 09:21:55
问题 I am confused about when controllers get instantiated. Also, how do controllers gets instantiated when nesting states. I might be confused how scope gets attached to view and controller, that is, if every view gets its own controller and scope or do they share the same scope. Can someone please explain when controllers get instantiated? Under nested routes do all the views share one controller and scope? What happens when I switch states and go back to a state does another controller get

Angular - ui-router get previous state

落花浮王杯 提交于 2019-12-17 08:00:55
问题 Is there a way to get the previous state of the current state? For example I would like to know what the previous state was before current state B (where previous state would have been state A). I am not able to find it in ui-router github doc pages. 回答1: ui-router doesn't track the previous state once it transitions, but the event $stateChangeSuccess is broadcast on the $rootScope when the state changes. You should be able to catch the prior state from that event ( from is the state you're

ngRoute not working

非 Y 不嫁゛ 提交于 2019-12-13 20:52:30
问题 My scripts are : index.html <!DOCTYPE html> <html ng-app="myApp"> <head> <title>My Application</title> </head> <body> <div ng-view></div> <script src="/assets/vendor/angular/angular-1.2.16.min.js"></script> <script src="/assets/vendor/angular/extras/angular-route.js"></script> <script src="/assets/myapp/myApp.js"></script> </body> </html> myApp.js (function () { angular.module('myApp', ['ngRoute']) .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {