0
我的理解是,通过view-model.ref,我可以从组件外部访问组件的视图模型,称之为功能。从Aurelia w/TypeScript组件外部调用组件视图模型函数时,“Can not read property of undefined”
下面的代码将导致无法读取属性 'LoadForAdditionalLocations' 未定义
成分的导入
export class UserLocationSelector {
public LoadForAdditionalLocations(reportLogin:string, addLocationsLogin:string){
///do stuff
}
}
页面组件上(TS文件)
export class AddLocation{
attached(){
this.UserLocationSelector.LoadForAdditionalLocations("user1","user2");
}
}
该组件处于打开状态的页面(htmlf ILE)
<template>
<require from='user-location-selector'></require>
<div>
<user-location-selector view-model.ref="UserLocationSelector"></user-location-selector>
</div>
</template>
我实际上是使用this.UserLocationSelector并导致相同的错误。 –
我已经添加了一个示例gist –
我可以使用javascript来使用它。不过在TypeScript中。 –