内部错误:消息:controllerFactory.createForCurrentScope不是函数

时间:2018-03-28 09:31:06

标签: validation typescript aurelia

我在aurelia视图模型中收到了上述错误

  

内部错误:消息:controllerFactory.createForCurrentScope不是   功能

这是代码,

export class UpdateClient {
    public httpClient: HttpClient;
    public router: Router;
    public clientHelper: ClientHelper;
    public validator: Validator;
    public canSave: boolean;
    public controller: ValidationController;    
    public client: Client ;

 constructor(httpClient: HttpClient, router: Router, clientValidator: ClientValidator, clientHelper: ClientHelper, controllerFactory: ValidationControllerFactory, validator: Validator) {
        this.httpClient = httpClient;
        this.clientHelper = clientHelper;
        this.router = router;
        this.client = new Client
        this.controller = controllerFactory.createForCurrentScope(validator);
        clientValidator.validate(this.client, clientHelper);
}

1 个答案:

答案 0 :(得分:1)

您需要@autoinject()UpdateClient或任何其他装饰器才能正确发出类型元数据。

ValidationControllerFactory已在DI中注册为模块文件中的解析器,因此只需导入(您拥有它,否则会出现类型错误)应该会给您正确的信息。

您可能需要仔细检查experimentalDecorators中是否emitDecoratorMetadatatsconfig.json设为真。

另外,请确保您在main.ts中注册验证插件,如下所示:

aurelia.use.plugin(PLATFORM.moduleName('aurelia-validation'))