2

I am developing an app in angular-2 in which I have index page which will load my app component. app component content the routing to load home or login.

here is my index.html

<!doctype HTML>
<html>

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
    <script src="/angular2/bundles/angular2-polyfills.js"></script>
    <script src="/systemjs/dist/system.src.js"></script>
    <script src="/rxjs/bundles/Rx.js"></script>
    <script src="/angular2/bundles/angular2.dev.js"></script>
    <script src="/angular2/bundles/upgrade.dev.js"></script>
    <style>
       *{
            border-radius: 0px !important;
        }
    </style>
</head>

<body>
    <div class="container">
      <app>Loading......</app>
    </div>
    <script>
       System.config({
            defaultJSExtensions: true,
        packages: {        
          app: {
            defaultExtension: 'js'
          }
        },
        paths: {
            'angular2/upgrade': '../node_modules/angular2/upgrade'
          }

      });
        System.import('scripts/src/bootstrap');
    </script>
</body>

</html>

here is my bootstrap.ts

//import {bootstrap} from 'angular2/angular2';
///<reference path="../node_modules/angular2/typings/node/node.d.ts" />
import {UpgradeAdapter} from 'angular2/upgrade';
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';


import {App} from './components/app/app';
import {LoginService} from './services/loginService';
import {HttpService} from './services/httpServices';

bootstrap(App, [HTTP_PROVIDERS, ROUTER_PROVIDERS, LoginService, HttpService]);

here is my app.ts

import {Component, View, Inject} from 'angular2/core';
import {Router, RouteConfig, RouterLink, RouterOutlet,  ROUTER_PROVIDERS} from 'angular2/router';


import {HomeComponent} from '../home/home';
import {LoginComponent} from '../login/login';

@Component({
    selector: 'app',
})
@View({
    templateUrl: '/scripts/src/components/app/app.html',
    directives: [RouterLink, RouterOutlet]
})
export class App {
    constructor( @Inject(Router) router: Router) {
        router.config([
            { path: '', as: 'home', component: HomeComponent },
            { path: '/login', as: 'login', component: LoginComponent }
        ]);
    }
}

which load my other component but when I run my app giving me error.

enter image description here

please, correct me what I am missing here.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Rhushikesh
  • 3,630
  • 8
  • 45
  • 82

1 Answers1

4

update (2.0.0 final)

@NgModule({
  providers [
    RouterModule.forRoot(myRoutes), 
    { provide: APP_BASE_HREF, useValue : 'path'}
  ],
  bootstrap: [AppComponent]
]); 

original

https://angular.io/docs/ts/latest/guide/router.html

Add the base element just after the <head> tag. If the app folder is the application root, as it is for our application, set the href value exactly as shown here.

<base href="/">

Alternatively add

bootstrap(AppComponent, [
  ROUTER_PROVIDERS, 
  provide(APP_BASE_HREF, {useValue : 'path'})
]); 

in your bootstrap.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567