当前位置: 首页 > 知识库问答 >
问题:

升级到angular2后路由器链路指令中断。0.0-beta。0

柴丰
2023-03-14

我在Angular 2中有这样一个组件(alpha版本49):

import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS,
    LocationStrategy, HashLocationStrategy} from 'angular2/router';

@RouteConfig([
    {path: '/DeleteProduct', as: 'DeleteProduct', component: DeleteProduct}
])

@Component({
    selector: 'app'
})
@View({
    directives: [ROUTER_DIRECTIVES],
    template: `
  <div>
      <nav class="navbar navbar-default">
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
              <ul class="nav navbar-nav navbar-right">
                <li><a [router-link]="['/DeleteProduct']">Add/Delete</a></li>
              </ul>
            </div>
          </div>
      </nav>

      <div>
        <router-outlet></router-outlet>
      </div>
  </div>
  `
})
export class App {
}

它工作得非常好。今天我把我的角版升级到了2.0.0-beta.0。现在上面的代码失败与消息:

Can't bind to 'router-link' since it isn't a known native property ("collapse-1">
. . . 
App@10:23
    at new t (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:6:5082)
    at e.parse (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:4350)
    at http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:20295
    at Zone.run (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:138:17)
    at Zone.run (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:4:14657)
    at zoneBoundFn (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:111:19)
    at lib$es6$promise$$internal$$tryCatch (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:1511:16)
    at lib$es6$promise$$internal$$invokeCallback (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:1523:17)
    at lib$es6$promise$$internal$$publish (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:1494:11)
    at http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:243:5

-----async gap-----
Error
    at _getStacktraceWithUncaughtError (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:2195:26)
    at Zone.fork (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:2253:40)
    at Zone.bind (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:109:48)
    at bindArguments (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:980:29)
    at lib$es6$promise$promise$$Promise.obj.(anonymous function) [as then] (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:1000:37)
    at e._compileComponentRuntime (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:20236)
    at e.componentTemplateFactory (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:20935)
    at e.createBeginComponent (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:15:2637)
    at e.visitElement (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:15:6099)
    at e.visit (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:14:23018)

-----async gap-----
Error
    at _getStacktraceWithUncaughtError (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:2195:26)
    at Zone.fork (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:2253:40)
    at Zone.bind (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:109:48)
    at bindArguments (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:980:29)
    at lib$es6$promise$promise$$Promise.obj.(anonymous function) [as then] (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:1000:37)
    at e._compileComponentRuntime (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:20236)
    at e.compileHostComponentRuntime (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:19425)
    at t.compileInHost (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:18:24265)
    at t.loadAsRoot (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:11:7604)
    at g.provide.useFactory (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:11:11883)

-----async gap-----
Error
    at _getStacktraceWithUncaughtError (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:2195:26)
    at Zone.fork (http://localhost:9000/node_modules/angular2/bundles/angular2-polyfills.js:2253:40)
    at e._createInnerZone (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:4:14446)
    at new e (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:4:11954)
    at i (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:11:12294)
    at t.application (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:11:14286)
    at Object.n [as bootstrap] (http://localhost:9000/node_modules/angular2/bundles/angular2.min.js:19:711)
    at execute (http://localhost:9000/dist/bootstrap.js:18:23)
    at u (http://localhost:9000/node_modules/systemjs/dist/system.js:5:97)
    at Object.execute (http://localhost:9000/node_modules/systemjs/dist/system.js:5:3188)

我在哪里犯了一个错误?更改日志对此只字未提。

共有2个答案

姬慎之
2023-03-14

指向此(camelCase)突破性更改的链接:

角度模板现在区分大小写,并使用camelCase代替kebab盒(破折号盒)

之前:

<p *ng-if="cond">
<my-cmp [my-prop]="exp">
<my-cmp (my-event)="action()">
<my-cmp [(my-prop)]="prop">
<input #my-input>
<template ng-for #my-item [ng-for-of]=items #my-index="index">

之后:

<p *ngIf="cond">
<my-cmp [myProp]="exp">
<my-cmp (myEvent)="action()">
<my-cmp [(myProp)]="prop">
<input #myInput>`,
<template ngFor="#myItem" [ngForOf]=items #myIndex="index">

和可观测问题的链接

Observable不再从angular2/core

之前

import {Observable} from 'angular2/core'

之后

import {Observable} from 'rxjs/Observable';
段干子晋
2023-03-14

路由器链接被重命名为routerLink,作为删除基于“-”的语法的一部分。

我这里有一个工作样本:http://www.syntaxsuccess.com/viewarticle/routing-in-angular-2.0

 类似资料:
  • 令人惊讶的是,在Google和StackOverflow中很难找到它,我在这里问,在React路由器中使用

  • 我一直在致力于将我们的应用程序从React.js 0.13升级到15.4.2以及与之相关的依赖项。我可能很接近,但经过4天50个小时后,我终于到了终点,我最后的希望。 在升级过程中,react路由器被升级到4.0.0版,每个文档、教程和堆栈溢出问题都显示了如何编写路由器(所有这些都必须是正确的),但是,当我这样做时,它总是失败。要么说历史是必需的属性,要么当我通过示例添加它时,它仍然显示为未定义和

  • 在以下React应用程序中,有两个路由URLhttp://myapp 正确布线到布局构件。但是,URLhttp://myapp/login 也路由到布局组件,而不是登录。如果我将path=“/login”更改为“/sign”,它将正确路由到登录组件。 React路由器中的“/login”路径将其路由到路由是否有特殊之处?或者我设置这个路由的方式有错误吗?

  • 我正在尝试将react router从v3升级到v4,运行应用程序时出现以下错误: 减速器: 商店: 索引:从“React”导入React; 路线: 应用程序: 我不知道我错过了什么才能让它发挥作用 **注意:即使我只有一个路由并呈现静态组件(带文本的单个div),我仍然会看到此错误

  • 所以我有一些路线,比如<code>/category/tech</code>和<code</categority/tech/new<code>和<code>/category/tech/old</code>等等 他们都使用 或者我必须分别定义它们,就像

  • 我正在使用react with react路由器。我正试图在react路由器的“链接”中传递属性 “链接”呈现页面,但不将属性传递给新视图。下面是查看代码 如何使用“链接”传递数据?