-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot.ts
More file actions
48 lines (39 loc) · 1.45 KB
/
boot.ts
File metadata and controls
48 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {Component,bind} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {Router,ROUTER_PROVIDERS,RouteConfig, ROUTER_DIRECTIVES,APP_BASE_HREF,LocationStrategy,RouteParams,ROUTER_BINDINGS} from 'angular2/router';
import { Ng1Bridge } from './ng1Bridge.ts';
@Component({
selector: 'my-app',
directives: [ROUTER_DIRECTIVES],
template: `
<h2>
Here, an Angular 2 with TypeScript inside Angular 1 app.
</h2>
<p>{{label}}</p>
<router-outlet></router-outlet>
`,
providers:[
Ng1Bridge
],
})
@RouteConfig([
//{path:'/component-first', name: 'ComponentFirst', component: ComponentFirst}
//{path:'/component-two', name: 'ComponentTwo', component: ComponentTwo}
])
export class AppComponent implements OnInit {
label: string;
constructor(router:Router, bridge:Ng1Bridge)
{
this.router=router;
this.bridge=bridge;
}
ngOnInit() {
var scp = this.bridge.globalScope; //--> ng1 $scope.myValue reference from the body scope
this.label = 'Ng2 accessing a Ng1 variable: "' + scp.myValue + '"';
//to retrieve an instance of any ng1 service, use:
// ** var userService = this.bridge.getService('userService'); the argument should be the name of the service injected on the ng1's scope
// ** userService.getLoggedUser() for example.
}
}
//bootstraping the Angular 2 application
bootstrap(AppComponent, [ROUTER_PROVIDERS,bind(APP_BASE_HREF).toValue(location.pathname)]);