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

Angular2 beta14 Typescript routerLink绑定错误[重复]

潘泳
2023-03-14
/// <reference path="angular2/typings/browser.d.ts" />
/// <reference path="angular2/core.d.ts" />
/// <reference path="angular2/router.d.ts" />

import {bootstrap} from 'angular2/platform/browser';
import {Component} from 'angular2/core';
import {ROUTER_PROVIDERS} from 'angular2/router';

import {Wizard1} from './wizard1';
import {Wizard2} from './wizard2';
import {Step1} from './step1';
import {Step2} from './step2';
import {Step3} from './step3';
import {Step4} from './step4';
import {Step5} from './step5';

@Component({
    selector: 'page',
    template:
'<div>
    <select (change)="setSelectedWizard($event.target.value)">
        <option *ngFor="#wizard of Wizards" [selected]="SelectedWizard == wizard" [value]="wizard.name" [routerLink]="'' + wizard.path + ''">{{wizard.name}}</option>
    </select>
    <wizard1>
        <step1>
            <h1>First!</h1>
        </step1>
        <step2>
            <h1>Second!</h1>
        </step2>
        <step3>
            <h1>Third!</h1>
        </step3>
        <step4>
            <h1>Fourth!</h1>
        </step4>
        <nav>
            <button type="button" value="Next" [class]="(SelectedStepIndex == Steps.length) ? 'btn btn-primary hidden' : 'btn btn-default'" (click)="next()" [routerLink]="['' + Steps[SelectedStepIndex] + '']">Next</button>
        </nav>
        <router-outlet></router-outlet>
    </wizard1>
    <wizard2>
        <step1>
            <h1>First!</h1>
        </step1>
        <step5>
            <h1>Fifth!</h1>
        </step5>
        <nav>
            <button type="button" value="Next" [class]="(SelectedStepIndex == Steps.length) ? 'btn btn-primary hidden' : 'btn btn-default'" (click)="next()" [routerLink]="['' + Steps[SelectedStepIndex] + '']">Next</button>
        </nav>
        <router-outlet></router-outlet>
    </wizard2>
    <router-outlet></router-outlet>
</div>'
})
export class Page {
    Wizards = [{name: 'wizard1', path:'/wizard1'}, {name: 'wizard2', path: '/wizard2'}];
    SelectedWizard = this.Wizards[0];

    setSelectedWizard(value) {
       this.SelectedWizard = value;
    }
}

bootstrap(Page, [ROUTER_PROVIDERS]);
bootstrap(Wizard1, [ROUTER_PROVIDERS]);
bootstrap(Wizard2, [ROUTER_PROVIDERS]);
bootstrap(Step1);
bootstrap(Step2);
bootstrap(Step3);
bootstrap(Step4);
bootstrap(Step5);
/// <reference path="angular2/core.d.ts" />
/// <reference path="angular2/router.d.ts" />

import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_PROVIDERS} from 'angular2/router';

@RouteConfig([
    { path: '/wizard1', name: 'wizard1', component: Wizard1 }
])
@Component({
    selector: 'wizard1',
    template:`<div><ng-content></ng-content></div>`
})
export class Wizard1 {
    Steps = ['/Step1', '/Step2', '/Step3', '/Step4'];
    SelectedStepIndex = 0;

    next() {
        ++this.SelectedStepIndex;
    }
}
/// <reference path="angular2/core.d.ts" />
/// <reference path="angular2/router.d.ts" />

import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_PROVIDERS} from 'angular2/router';

@RouteConfig([
    { path: '/wizard2', name: 'wizard2', component: Wizard2 }
])
@Component({
    selector: 'wizard2',
    template:`<div><ng-content></ng-content></div>`
})
export class Wizard2 {
    Steps = ['/Step1', '/Step5'];
    SelectedStepIndex = 0;

    next() {
        ++this.SelectedStepIndex;
    }
}
/// <reference path="angular2/core.d.ts" />
/// <reference path="angular2/router.d.ts" />

import {Component} from 'angular2/core';
import {RouteConfig} from 'angular2/router';

@RouteConfig([
    { path: '/Step1', name: 'Step1', component: Step1 }
])
@Component({
    selector: 'step1',
    template: `<div><ng-content></ng-content></div>`
})
export class Step1 {

}

怎么回事?为什么这不起作用?

环境

  1. Visual Studio 2015更新1
  2. ASP.NET 5和MVC6
  3. DNX 4.5.1和5.0
  4. Angular2打字稿

共有1个答案

伏子辰
2023-03-14
import {ROUTER_PROVIDERS, ROUTER_DIRECTIVES} from 'angular2/router';
@Component({
    selector: 'page',
    //....
    //other options
    //....
    directives: [ROUTER_DIRECTIVES]
})
 类似资料:
  • 问题内容: 我正在创建一个词解析类,并在运行此命令时始终收到“ < main .Word_Parser实例位于0x1037dd3b0>的绑定方法Word_Parser.sort_word_list ”的错误: 问题答案: 这里没有错误。您正在打印一个函数,这就是函数的外观。 要实际 调用 该函数,必须在其后放置括号。您已经在上面完成了。如果要打印调用函数的结果,只需让函数返回值,然后将打印内容放在

  • 在应用程序运行时,我遇到了以下错误:System. Windows. Data Error: 4:找不到引用“RelativeSource FindAncestor, AncestorType=‘System. Window. Control. ItemsControl’, AncestorLine=‘1’的绑定源。Binding表达式:路径=HorizontalContent的对齐;数据项=空;

  • 我得到了这个错误,我知道它的意思 DL已弃用,请使用Fiddle DL已被弃用,请使用Fiddle获取源索引从 rubygems.org/由于错误(2/3)而重试源获取: Bundler::Fetcher::CertificateFailureER ror无法验证<--的SSL 证书plhd--3/>您可能遇到中间人攻击,但最有可能的是您的系统没有验证所需的CA证书。有关 OpenSSL证书的信息

  • 请帮助我,我是python新手,现在了解下面的错误 “TypeError:必须使用ExampleScript14实例作为第一个参数调用未绑定的方法assertEqual()(改为使用Get-str实例)” 有关以下代码: 从selenium从selenium导入webdriver。网络驱动程序。常见的按导入按导入单元测试导入时间从时间导入睡眠导入变量

  • 当我尝试在eclipse中运行junit测试时,出现以下错误: SLF4J:类路径包含多个SLF4J绑定。SLF4J:在[jar: file:/C:/User/MaximilianBecker/. m2/repository/uk/org/lidalia/slf4j-test/1.2.0/slf4j-test-1.2.0.jar中找到绑定! /org/slf4j/impl/StaticLogger