顯然,Angular2的beta版比新的要新,因此那里沒有太多的信息,但是我正在嘗試做一些我認為比較基本的路由。從https://angular.io網站竊取快速入門代碼和其他代碼片段導致了以下文件結構:angular-testapp/ app/ app.component.ts boot.ts routing-test.component.ts index.html文件填充如下:index.html<html> <head> <base href="/"> <title>Angular 2 QuickStart</title> <link href="../css/bootstrap.css" rel="stylesheet"> <!-- 1. Load libraries --> <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="node_modules/rxjs/bundles/Rx.js"></script> <script src="node_modules/angular2/bundles/angular2.dev.js"></script> <script src="node_modules/angular2/bundles/router.dev.js"></script> <!-- 2. Configure SystemJS --> <script> System.config({ packages: { app: { format: 'register', defaultExtension: 'js' } } }); System.import('app/boot') .then(null, console.error.bind(console)); </script> </head> <!-- 3. Display the application --> <body> <my-app>Loading...</my-app> </body></html>引導程序import {bootstrap} from 'angular2/platform/browser'import {ROUTER_PROVIDERS} from 'angular2/router';import {AppComponent} from './app.component'bootstrap(AppComponent, [ ROUTER_PROVIDERS]);app.component.tsimport {Component} from 'angular2/core';import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from 'angular2/router';import {RoutingTestComponent} from './routing-test.component';@Component({ selector: 'my-app', template: ` <h1>Component Router</h1> <a [routerLink]="['RoutingTest']">Routing Test</a> <router-outlet></router-outlet> `})我在這里發現了一個模糊的相關問題;升級到angular2.0.0-beta.0后,router-link指令中斷。但是,答案之一中的“有效示例”是基于beta版的代碼-可能仍然可以使用,但是我想知道為什么我創建的代碼不起作用。
3 回答

HUH函數
TA貢獻1836條經驗 獲得超4個贊
使用Visual Studio進行編碼時的警告語(2013)
我已經浪費了4至5個小時來嘗試調試此錯誤。我嘗試通過字母找到在stackoverflow上找到的所有解決方案,但仍然出現此錯誤:Can't bind to 'routerlink' since it isn't a known native property
請注意,在復制/粘貼代碼時,Visual Studio有自動格式化文本的討厭習慣。我總是從VS13得到一個小的瞬時調整(駱駝的情況消失了)。
這個:
<div>
<a [routerLink]="['/catalog']">Catalog</a>
<a [routerLink]="['/summary']">Summary</a>
</div>
成為:
<div>
<a [routerlink]="['/catalog']">Catalog</a>
<a [routerlink]="['/summary']">Summary</a>
</div>
差異很小,但足以觸發錯誤。最丑陋的部分是,每次我復制粘貼時,這種微小的差異一直在避免我的注意。碰巧的機會,我看到了這個微小的區別并解決了。
- 3 回答
- 0 關注
- 803 瀏覽
添加回答
舉報
0/150
提交
取消