angular2-routing

Angular Router example Best way to upgrade to include .angular-cli.json and bypass Cannot read property 'config' of null

折月煮酒 提交于 2019-12-01 14:16:08
I tried downloading the Routing and Navigation example from this page Here's the link to the specific zip . I run the following sequence of commands: npm install npm install --save-dev @angular/cli@latest ng -v ng serve -o From what I can make out Cannot read property 'config' of null is somehow related to a bad version of the CLI. But if I create a new project I can start it successfully with my existing setup ng new router cd router npm install ng serve -o Old directory structure (from zip download) includes these files: bs-config.json e2e-spec.ts New directory structure (from ng new):

When to use @angular tags in Angular 2? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-01 14:14:00
This question already has an answer here: What is @angular in Angular 2? 5 answers I was trying to bootstrap my application using code below in a boot.ts file: import {bootstrap} from 'angular2/platform/browser' import {ROUTER_PROVIDERS} from 'angular2/router' import {AppComponent} from './app.component' bootstrap(AppComponent,[ROUTER_PROVIDERS]); It worked fine. Now I wanted to try and add Google Maps so imported angular2-google-maps package , created a map.component.ts file and added this to the router mapping (defined in the app.component.ts file). For the above package, import {bootstrap}

Why do my angular2 components get re-instantiated each time I change the route?

大憨熊 提交于 2019-12-01 14:09:15
问题 I am trying to put together a demo app of Angular 2 + Rx.JS 5/Next. I noticed that my components are re-instantiated each time I switch the route. Here is the code for the root app: import {bootstrap} from 'angular2/platform/browser'; import {HTTP_PROVIDERS} from 'angular2/http'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component.ts'; bootstrap(AppComponent, [HTTP_PROVIDERS, ROUTER_PROVIDERS]); Here is the code for the root component: import

Twitter widget on Angular 2

徘徊边缘 提交于 2019-12-01 13:43:56
I created a Twitter widget and I'm trying to put it in my Angular 2 project, but the JS file does not work. If I insert it with JS ( Here ) it works, but when I switch to another tab and back (I have Angular Routing installed) it disappears and shows whatever is in A tag (so, "Tweets by ..."). HTML code (it's in home component): <md-card-content> <a class="twitter-timeline" data-lang="en" data-height="350" data-theme="light" data-chrome="noborders nofooter noheader noscrollbar transparent" href="https://twitter.com/profile">Tweets by profile</a> </md-card-content> Script in home.component.ts,

When to use @angular tags in Angular 2? [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-01 12:40:44
问题 This question already has answers here : What is @angular in Angular 2? (5 answers) Closed 3 years ago . I was trying to bootstrap my application using code below in a boot.ts file: import {bootstrap} from 'angular2/platform/browser' import {ROUTER_PROVIDERS} from 'angular2/router' import {AppComponent} from './app.component' bootstrap(AppComponent,[ROUTER_PROVIDERS]); It worked fine. Now I wanted to try and add Google Maps so imported angular2-google-maps package , created a map.component.ts

Sending whole object from one component to another in angular 2

不羁岁月 提交于 2019-12-01 12:31:35
问题 I have a problem. I don't know how to send object from one component to another. In first component cinema.component.html I have following function call: <a title="Reserve" (click)="openReservationPage(repertoire)">Reserve</a> In cinema.component.ts file, for that .html I have something like: openReservationPage(repertoire: UpcomingRepertoire) { this.router.navigate(['/reserve', {repertoire: JSON.stringify(repertoire)}]); } My app.routes.ts file contains appropriate routing: { path: 'reserve'

Angular2 different route parameters

ぃ、小莉子 提交于 2019-12-01 12:26:32
问题 I want to have multiple functions in my appication activated through different parameters. The problem is that I have to distinguish between the routes. At the moment I need these routes: /employee-management/department/new /employee-management/department/delete , /employee-management/employee/new , /employee-management/employee/delete /employee-management/employee/<id> Here is my current implementation. But I am doing something wrong. As example when I do /employee/new it goes into the first

Angular2 different route parameters

梦想与她 提交于 2019-12-01 12:05:25
I want to have multiple functions in my appication activated through different parameters. The problem is that I have to distinguish between the routes. At the moment I need these routes: /employee-management/department/new /employee-management/department/delete , /employee-management/employee/new , /employee-management/employee/delete /employee-management/employee/<id> Here is my current implementation. But I am doing something wrong. As example when I do /employee/new it goes into the first if with the if(params['id']) instead of the if(params['option']) where it should go because new is an

How to access Angular2 new router querystring

十年热恋 提交于 2019-12-01 11:43:46
问题 How can I access the querystring parameters from my component? I have URLs like this: http://myurl.com/myroute?myparam=1 thanks 回答1: Hint The RC.1 @angular/router is also deprecated. It's better to stick with @angular/router-deprecated (because it has more features and is quite stable) until a new new router is shipped. If you are using router-deprecated then constructor(private params: RouteParams) will give you access to all parameters, then you can get specific parameter by params.get(

Angular 2 - Route guard not working on browser refresh

我是研究僧i 提交于 2019-12-01 10:43:53
Having these routes defined in app.module.ts ... { path: 'mypath', component: MyComponent, canActivate: [RouteGuard] }, { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: '**', redirectTo: '/home'} and this guard service import { Injectable } from '@angular/core'; import { CanActivate } from '@angular/router'; import { AngularFire } from 'angularfire2'; import { AngularFireAuth } from 'angularfire2'; @Injectable() export class RouteGuard implements CanActivate { private loggedIn: boolean; constructor ( private af: AngularFire, private auth: AngularFireAuth ) {} canActivate():