2015-10-28 2 views
0

Попытка работать с маршрутизатором angular2 и до сих пор ничего работы после попытки много примеров ...Angular2 маршрутизатор - как заставить его работать правильно

я использую Альфа 44

здесь супер ошибка полезно: Regex

Hide network messages 
All 
Errors 
Warnings 
Info 
Logs 
Debug 
Handled 
. 
angular2.dev.js:21835 TypeError: Cannot read property 'toString' of undefined(…) 
angular2.dev.js:10713 ## _onError ## 
angular2.dev.js:10714 TypeError: Cannot read property 'get' of undefined 
    at angular2.dev.js:19620 
    at Zone.run (angular2.dev.js:138) 
    at Zone.run (angular2.dev.js:10644) 
    at NgZone.run (angular2.dev.js:10607) 
    at ApplicationRef_.bootstrap (angular2.dev.js:19615) 
    at Object.commonBootstrap (angular2.dev.js:26650) 
    at Object.bootstrap (angular2.dev.js:27475) 
    at execute (app/bootstrap.ts!transpiled:15) 
    at p (system.js:4) 
    at Object.execute (system.js:5) 
angular2.dev.js:138 Error: Cannot read property 'get' of undefined(…) 

вот мой код в данный момент:

bootstrap.ts

import {App} from './app.ts'; 
import {bootstrap} from 'angular2/angular2'; 
import {routerInjectable} from 'angular2/router'; 

bootstrap(App, [routerInjectable]); 

index.html

<html> 
<head> 
    <title>Angular 2 Todo App</title> 

    <link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet" /> 
    <link href="node_modules/font-awesome/css/font-awesome.css" rel="stylesheet" /> 

    <script src="https://code.angularjs.org/tools/system.js"></script> 
    <script src="https://code.angularjs.org/tools/typescript.js"></script> 
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script> 
    <script src="node_modules/angular2/bundles/router.dev.js"></script> 

    <script src="node_modules/lodash/index.js"></script> 

    <script> 
     System.config({ 
      transpiler: 'typescript', 
      typescriptOptions: { emitDecoratorMetadata: true } 
     }); 

     System.import('./app/bootstrap.ts').catch(console.error.bind(console)); 
    </script> 
</head> 


<body style="padding-top: 50px;"> 
    <app>Loading...</app> 
</body> 
</html> 

, что я делаю неправильно?

+0

'routerInjectable' супер старый, использование' ROUTER_PROVIDERS'. –

ответ

3

мне нужно задать вопрос .... найти ответ через несколько минут на GitHub;)

Вот решение, которое работает

import {App} from './app.ts'; 
import { bootstrap, provide, FORM_PROVIDERS } from 'angular2/angular2'; 
import { ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy } from 'angular2/router'; 

bootstrap(App, [ 
    ROUTER_PROVIDERS, 
    FORM_PROVIDERS, 
    provide(LocationStrategy, { useClass: HashLocationStrategy }) 
]).then(
    success => console.log('App Bootstrapped!'), 
    error => console.log(error) 
); 
+0

Обратите внимание, что 'bind' тоже устарел, вместо этого используйте' предоставлять': 'обеспечить (LocationStrategy, {useClass: HashLocationStrategy});' –

+1

7 отредактировал мой ответ, thx, я даже не знал, что он устарел! –

Смежные вопросы