angular-routing

Angular2 Router: add hashtag to url

大兔子大兔子 提交于 2019-12-05 23:58:31
I'm using Angular2 Seed application, and you can find it in the official repo . As you can see, here we have angular2/router imported, and we're using it to create the basic routing of the application. import {Component, ViewEncapsulation} from 'angular2/angular2'; import { RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router'; ... @RouteConfig([ { path: '/', component: HomeCmp, as: 'Home' }, { path: '/about', component: AboutCmp, as: 'About' } ]) export class AppCmp {} My question is: how can I configure router to add hashtag in my url, to make it looks like: localhost:5555/#/about . Is

AngularJS routing with templateUrl

荒凉一梦 提交于 2019-12-05 20:33:39
问题 I have a problem with the AngularJS routing: I don't get any feedback of the page. No errors or view-switches. I checked my implementation of the module, but it's declared in the right way. Then I searched for typos such as templateURL , but I didn't find any. I also tried to use ng-href instead of href in the list, but then the links weren't clickable anymore. Here is my plunker. And my code: Created my navigation: <body ng-app="Productportfolio"> <ul> <li> <a href="#/home">Home</a> </li>

AngularJS, How about multiple routes with different templates but the same controller?

六眼飞鱼酱① 提交于 2019-12-05 19:47:20
i'm investigating if i can have what the title says. Here's my thought. Let's assume that i've got this routes: .when('/', { templateUrl : 'partials/homepage.html', }) .when('/test', { templateUrl : 'partials/test.html', }) .when('/page/:pageID', { templateUrl : 'partials/page.html', }) .when('/page/single/:pageID', { templateUrl : 'partials/page-single.html', }) Until now i had the opportunity to add the templateUrl as also the controller details in the route and everything was working just fine. Now the app is changed and there is only one controller with all the information needed and must

Angular 2 opening a static page

南楼画角 提交于 2019-12-05 18:32:39
I have angular 2 project. I want to open static help files available on server in new window. I tried window.open(help/index.html) . It navigates to the page but throws error about route not found. I have also tried to run above code outside angular zone but makes no difference. I suspect as browser location changes angular detects it in next change detection cycle and try to route to that URL. What could be done to achieve this. You could try and leverage the name parameter of the window.open() method which is the equivalent of the target attribute in anchor tags. window.open("help/index.html

Angular - Lazy loading a module inside module with a child route

倖福魔咒の 提交于 2019-12-05 14:33:04
I have an angular application where my main routing module lazy loads modules correctly. I do however now have an additional requirement of displaying another component / module inside one of the lazy loaded modules. When I now navigate to users/id (this part works correctly) I want a tab view in the HTML where I can load additional modules based on what tab is clicked on. For example, I might have 3 buttons: User Albums , User Favourites and User Stats . When I click on one of those, I want a component to display on the same page as a child using the <router-outlet></router-outlet> App

Passing multiple parameters in an AngularJS route

会有一股神秘感。 提交于 2019-12-05 12:37:19
I am trying to implement a angular route which should have multiple parameters. Here is an example of what I tried: .when('/myRoute/paramA/:paramA/paramB/:paramB/paramC/:paramC', { templateUrl: 'abc.html', controller: 'pwrController as pwrCtrl' }); Now the problem in this is that I need to always pass paramA in order to pass paramB. And paramA and paramB in order to pass paramC. Is there any way in angular where I can pass paramA, paramB or paramC independently ? Thanks. ! inject $location into your controllers and use that instead of routeParams var paramA = 'something'; $location.search(

Angular ui-router fails to resolve named dependencies

淺唱寂寞╮ 提交于 2019-12-05 10:00:29
问题 I recently migrated from ui-router 0.0.1 to 0.2.0. Since the migration, ui-router fails to resolve named dependencies that needs to be injected into a view's controller. Here's the sample code which works fine with ver 0.0.1 but fails in ver 0.2.0 angular.module( 'sample.test', [ 'ui.router', 'i18nService' ]) .config(function config($stateProvider) { $stateProvider.state( 'mystate', { url: '/mystate', resolve: {i18n: 'i18nService'}, views: { 'main': { controller: 'MyCtrl', templateUrl:

Angular - Apply style to element depending on sibling RouterLinkActive?

孤者浪人 提交于 2019-12-05 09:16:47
I do not have only one menu bar on my app that I need to be painted when the user navigates, I have another components too that needs to be painted as well. Can I achieve this just using routerLinkActive ? menu.html <menu> <a routerLink="page1" routerLinkActive="active"> option1 </a> <a routerLink="page2" routerLinkActive="active"> option2 </a> </menu> This menu works great. But what I'm asking is how can I take advantage of routerLinkActive property placed in other HTML Tag. like: main.html <main> <span class="title" routerLinkActive="active">My sub child part</span> </main> You could bind

Angular using $routeParams in Page title

a 夏天 提交于 2019-12-05 08:29:10
I found this answer in another SO question. But i would like to also use route parameters in some of the page titles. If i have a $routeProvider like this: $routeProvider.when('/demo/:name/:idNumber', {title : ' - :name', templateUrl: 'partials/details.html', controller: 'AppDetails'}); how do I match the :name in the title to the :name in the location? I tried the following .run(['$location', '$rootScope', '$routeParams', function($location, $rootScope, $routeParams) { $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { if(current.$$route.title.contains(":")){ //Not

Routing to sub routing module without lazy loading

与世无争的帅哥 提交于 2019-12-05 04:34:27
I want to have multiple routing modules in order to keep my application clean and easy to read. I currently use lazy loading for the SubComponent but I don't want to do this. So I am looking for a way to change this. Anyways, here is the currently working code. I have the following two routing files. app-routing.module.ts : import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'sub', loadChildren: './sub/sub.module#SubModule' } ]; @NgModule({ imports: [RouterModule.forRoot