我在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);
}
答案 0 :(得分:1)
您需要@autoinject()
类UpdateClient
或任何其他装饰器才能正确发出类型元数据。
ValidationControllerFactory
已在DI中注册为模块文件中的解析器,因此只需导入(您拥有它,否则会出现类型错误)应该会给您正确的信息。
您可能需要仔细检查experimentalDecorators
中是否emitDecoratorMetadata
和tsconfig.json
设为真。
另外,请确保您在main.ts
中注册验证插件,如下所示:
aurelia.use.plugin(PLATFORM.moduleName('aurelia-validation'))