Angular2异常:由于它不是已知的本机属性,因此无法绑定到“ routerLink”

显然,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.ts


import {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版的代码-可能仍然可以使用,但是我想知道为什么我创建的代码不起作用。

鸿蒙传说
浏览 714回答 3
3回答

HUH函数

使用Visual Studio进行编码时的警告语(2013)我已经浪费了4至5个小时来尝试调试此错误。我尝试通过字母找到在stackoverflow上找到的所有解决方案,但仍然出现此错误:Can't bind to 'routerlink' since it isn't a known native property请注意,在复制/粘贴代码时,Visual Studio有自动格式化文本的讨厌习惯。我总是从VS13得到一个小的瞬时调整(骆驼的情况消失了)。这个:<div>&nbsp; &nbsp; <a [routerLink]="['/catalog']">Catalog</a>&nbsp; &nbsp; <a [routerLink]="['/summary']">Summary</a></div>成为:<div>&nbsp; &nbsp; <a [routerlink]="['/catalog']">Catalog</a>&nbsp; &nbsp; <a [routerlink]="['/summary']">Summary</a></div>差异很小,但足以触发错误。最丑陋的部分是,每次我复制粘贴时,这种微小的差异一直在避免我的注意。碰巧的机会,我看到了这个微小的区别并解决了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

AngularJS