Skip to content

fix(app): types yo #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ dist
public/__build__/**
.webpack.json


build/
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</head>
<body>

<app>
<auth-app>
Loading...
</app>
</auth-app>

<!-- Commmon files to be cached -->
<script src="/build/common.js"></script>
Expand Down
18 changes: 12 additions & 6 deletions src/app/LoggedInOutlet.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import {Directive} from 'angular2/angular2';
import {RouterOutlet} from 'angular2/router';
import {Directive, Attribute, ElementRef, DynamicComponentLoader} from 'angular2/angular2';
import {Router, RouterOutlet} from 'angular2/router';
import {Injector} from 'angular2/di';
import {Login} from '../login/login';

@Directive({selector: 'loggedin-router-outlet'})
export class LoggedInOutlet extends RouterOutlet {
publicRoutes: any;
publicRoutes: any
constructor(
elementRef: ElementRef,
_loader: DynamicComponentLoader,
_parentRouter: Router,
_injector: Injector,
@Attribute('name') nameAttr: string) {

constructor(viewContainer, loader, router, injector, name) {
super(viewContainer, loader, router, injector, name);
super(elementRef, _loader, _parentRouter, _injector, nameAttr);
this.publicRoutes = {
'/login': true,
'/signup': true
}
}

canActivate(instruction) {
var url = this._router.lastNavigationAttempt;
var url = this._parentRouter.lastNavigationAttempt;
if (!this.publicRoutes[url] && !localStorage.getItem('jwt')) {
instruction.component = Login;
}
Expand Down
10 changes: 5 additions & 5 deletions src/home/home.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div class="home">
<div class="jumbotron centered">
<h1>Welcome to the angular2 authentication sample!</h1>
<h2 *if="jwt">Your JWT is:</h2>
<pre *if="jwt" class="jwt"><code>{{ jwt }}</code></pre>
<pre *if="jwt" class="jwt"><code>{{ decodedJwt | json }}</code></pre>
<h2 *ng-if="jwt">Your JWT is:</h2>
<pre *ng-if="jwt" class="jwt"><code>{{ jwt }}</code></pre>
<pre *ng-if="jwt" class="jwt"><code>{{ decodedJwt | json }}</code></pre>
<p>Click any of the buttons to call an API and get a response</p>
<p><a class="btn btn-primary btn-lg" role="button" (click)="callAnonymousApi()">Call Anonymous API</a></p>
<p><a class="btn btn-primary btn-lg" role="button" (click)="callSecuredApi()">Call Secure API</a></p>
<p><a class="btn btn-primary btn-lg" role="button" (click)="logout()">Logout</a></p>
<h2 *if="response">The response of calling the <span class="red">{{api}}</span> API is:</h2>
<h3 *if="response">{{response}}</h3>
<h2 *ng-if="response">The response of calling the <span class="red">{{api}}</span> API is:</h2>
<h3 *ng-if="response">{{response}}</h3>
</div>
</div>
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { bind } from 'angular2/di';
import { PipeRegistry } from 'angular2/change_detection';

import { App } from './app/app';
import { pipes } from './utils/pipes/pipes';

bootstrap(
App,
[
shadowDomInjectables,
formInjectables,
routerInjectables,
bind(PipeRegistry).toValue(new PipeRegistry(pipes))
routerInjectables
]
);
27 changes: 25 additions & 2 deletions typings/_custom/ng2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ declare module "angular2/src/router/location" {
declare module "angular2/router" {
class Instruction {}
class Router {
_registry: any;
_pipeline: any;
parent: any;
hostComponent: any;
navigating: boolean;
lastNavigationAttempt: string;
previousUrl: string;
_currentInstruction: any;
_outlets: any;
_subject: any;
navigate(url: string): Promise<any>;
config(config: any): Promise<any>;
deactivate(): Promise<any>;
Expand All @@ -141,10 +151,23 @@ declare module "angular2/router" {
parent: Router;
}
class RouterOutlet {
_router: Router;
constructor(elementRef: any, _loader: any, _parentRouter: any, _injector: any, nameAttr: any)
_loader: any;
_parentRouter: any;
_injector: any;
_childRouter: any;
_componentRef: any;
_elementRef: any;
_currentInstruction: any;
/**
* Given an instruction, update the contents of this viewport.
*/
activate(instruction: any): any;
deactivate(): any;
canDeactivate(instruction: any): any;
}
class RouteParams {}
var RouterLink: any;
var RouteParams: any;
var routerInjectables: any;
var RouteConfigAnnotation: any;
var RouteConfig: any;
Expand Down