Skip to content

Commit ec45a94

Browse files
committed
Merge pull request #17 from gdi2290/ts
fix(app): types yo
2 parents 3057ec4 + 3ff6a4d commit ec45a94

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ dist
3737
public/__build__/**
3838
.webpack.json
3939

40+
41+
build/

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
</head>
1919
<body>
2020

21-
<app>
21+
<auth-app>
2222
Loading...
23-
</app>
23+
</auth-app>
2424

2525
<!-- Commmon files to be cached -->
2626
<script src="/build/common.js"></script>

src/app/LoggedInOutlet.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
import {Directive} from 'angular2/angular2';
2-
import {RouterOutlet} from 'angular2/router';
1+
import {Directive, Attribute, ElementRef, DynamicComponentLoader} from 'angular2/angular2';
2+
import {Router, RouterOutlet} from 'angular2/router';
3+
import {Injector} from 'angular2/di';
34
import {Login} from '../login/login';
45

56
@Directive({selector: 'loggedin-router-outlet'})
67
export class LoggedInOutlet extends RouterOutlet {
7-
publicRoutes: any;
8+
publicRoutes: any
9+
constructor(
10+
elementRef: ElementRef,
11+
_loader: DynamicComponentLoader,
12+
_parentRouter: Router,
13+
_injector: Injector,
14+
@Attribute('name') nameAttr: string) {
815

9-
constructor(viewContainer, loader, router, injector, name) {
10-
super(viewContainer, loader, router, injector, name);
16+
super(elementRef, _loader, _parentRouter, _injector, nameAttr);
1117
this.publicRoutes = {
1218
'/login': true,
1319
'/signup': true
1420
}
1521
}
1622

1723
canActivate(instruction) {
18-
var url = this._router.lastNavigationAttempt;
24+
var url = this._parentRouter.lastNavigationAttempt;
1925
if (!this.publicRoutes[url] && !localStorage.getItem('jwt')) {
2026
instruction.component = Login;
2127
}

src/home/home.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div class="home">
22
<div class="jumbotron centered">
33
<h1>Welcome to the angular2 authentication sample!</h1>
4-
<h2 *if="jwt">Your JWT is:</h2>
5-
<pre *if="jwt" class="jwt"><code>{{ jwt }}</code></pre>
6-
<pre *if="jwt" class="jwt"><code>{{ decodedJwt | json }}</code></pre>
4+
<h2 *ng-if="jwt">Your JWT is:</h2>
5+
<pre *ng-if="jwt" class="jwt"><code>{{ jwt }}</code></pre>
6+
<pre *ng-if="jwt" class="jwt"><code>{{ decodedJwt | json }}</code></pre>
77
<p>Click any of the buttons to call an API and get a response</p>
88
<p><a class="btn btn-primary btn-lg" role="button" (click)="callAnonymousApi()">Call Anonymous API</a></p>
99
<p><a class="btn btn-primary btn-lg" role="button" (click)="callSecuredApi()">Call Secure API</a></p>
1010
<p><a class="btn btn-primary btn-lg" role="button" (click)="logout()">Logout</a></p>
11-
<h2 *if="response">The response of calling the <span class="red">{{api}}</span> API is:</h2>
12-
<h3 *if="response">{{response}}</h3>
11+
<h2 *ng-if="response">The response of calling the <span class="red">{{api}}</span> API is:</h2>
12+
<h3 *ng-if="response">{{response}}</h3>
1313
</div>
1414
</div>

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import { bind } from 'angular2/di';
88
import { PipeRegistry } from 'angular2/change_detection';
99

1010
import { App } from './app/app';
11-
import { pipes } from './utils/pipes/pipes';
1211

1312
bootstrap(
1413
App,
1514
[
1615
shadowDomInjectables,
1716
formInjectables,
18-
routerInjectables,
19-
bind(PipeRegistry).toValue(new PipeRegistry(pipes))
17+
routerInjectables
2018
]
2119
);

typings/_custom/ng2.d.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ declare module "angular2/src/router/location" {
129129
declare module "angular2/router" {
130130
class Instruction {}
131131
class Router {
132+
_registry: any;
133+
_pipeline: any;
134+
parent: any;
135+
hostComponent: any;
136+
navigating: boolean;
137+
lastNavigationAttempt: string;
138+
previousUrl: string;
139+
_currentInstruction: any;
140+
_outlets: any;
141+
_subject: any;
132142
navigate(url: string): Promise<any>;
133143
config(config: any): Promise<any>;
134144
deactivate(): Promise<any>;
@@ -141,10 +151,23 @@ declare module "angular2/router" {
141151
parent: Router;
142152
}
143153
class RouterOutlet {
144-
_router: Router;
154+
constructor(elementRef: any, _loader: any, _parentRouter: any, _injector: any, nameAttr: any)
155+
_loader: any;
156+
_parentRouter: any;
157+
_injector: any;
158+
_childRouter: any;
159+
_componentRef: any;
160+
_elementRef: any;
161+
_currentInstruction: any;
162+
/**
163+
* Given an instruction, update the contents of this viewport.
164+
*/
165+
activate(instruction: any): any;
166+
deactivate(): any;
167+
canDeactivate(instruction: any): any;
145168
}
169+
class RouteParams {}
146170
var RouterLink: any;
147-
var RouteParams: any;
148171
var routerInjectables: any;
149172
var RouteConfigAnnotation: any;
150173
var RouteConfig: any;

0 commit comments

Comments
 (0)