Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Aurelia 为什么我';我没有在激活方法中获取参数?_Aurelia - Fatal编程技术网

Aurelia 为什么我';我没有在激活方法中获取参数?

Aurelia 为什么我';我没有在激活方法中获取参数?,aurelia,Aurelia,我有三节课要上。首先,家长: import { Router, RouterConfiguration } from 'aurelia-router'; export class MainPage { router: Router; configureRouter(config: RouterConfiguration, router: Router) { config.map([ { route: '', redirect:

我有三节课要上。首先,家长:

import { Router, RouterConfiguration } from 'aurelia-router';

export class MainPage
{
    router: Router;

    configureRouter(config: RouterConfiguration, router: Router)
    {
        config.map([
            { route: '', redirect: 'entities' },
            { route: 'entities', name: 'entities', moduleId: './entities/entities', nav: true, title: 'Entities' },
            { route: 'structures', name: 'structures', moduleId: './structures/structures', nav: true, title: 'Data Structures' },
        ]);

        this.router = router;
    }
}
然后大哥哥:

import { Router, RouterConfiguration } from 'aurelia-router';

export class Entities
{
    private router: Router;

    configureRouter(config: RouterConfiguration, router: Router)
    {
        config.map([
            { route: '', name: 'entities-list', moduleId: './list', nav: true, title: 'Entities' },
            { route: ':name/events', name: 'entity-events', moduleId: './events', nav: true, title: 'Events' },
        ]);

        this.router = router;
    }
}
最后是小妹妹:

import { inject, computedFrom } from 'aurelia-framework';
import { Services } from './services';

@inject(Services)
export class Event
{
    private events = [];

    constructor(private services : Services) {}

    async attached(params, routeConfig)
    {
        debugger;
        this.events = <any> await this.services.getEvents(params.name);
    }
}
this.router.navigateToRoute('entity-events', { name: "Some Name" });
但是当我到达
调试器
断点时,没有
参数
,它是
未定义的
。根据文档,应该有一个传递给
activate
方法的对象,包含路由的参数。哪里出错了?

使用
激活
方法。
params参数被传递到
activate
,而不是像上面写的那样附加在

async activate(params, routeConfig)
{
    debugger;
    this.events = <any> await this.services.getEvents(params.name);
}
异步激活(参数,routeConfig)
{
调试器;
this.events=等待this.services.getEvents(params.name);
}

虽然你在问题中提到了
激活
,但我想这不是一个真正的问题,只是一个打字错误。昨晚我似乎太累了!我在试图弄明白为什么我的
activate
(是的,真的,
activate
)不起作用时遇到了这个问题:)。事实证明,如果我删除
async
,它确实可以工作,但是这里的示例使用
async
参数是否支持
async