我一直在浏览[Platypi.io/docs/getting-started/] [1]但是已经陷入关于添加功能的部分,以允许用户注册演示应用程序(https://platypi.io/docs/getting-started/allow-users-to-register)< / p>
具体步骤是
现在,让我们添加我们的寄存器功能。点击或点击平台按钮时将触发此功能。在模板中,我们通过在plat-tap属性中指定一个函数来定义按钮的tap事件。函数名称是寄存器,因此单击该按钮时,将在ViewControl上触发寄存器功能。将注册函数添加到视图控件(在public / viewcontrols / register / register.viewcontrol.ts中:
register() {
this.context.error = '';
this.userRepository.register(this.context.email,
this.context.password,
this.context.firstname,
this.context.lastname)
.then((success) => {
this.navigator.navigate(HomeViewControl);
}).catch((error) => {
this.context.error = error;
});
}
我在哪里添加此功能?如果我将它放在RegisterViewControl(如[this] [2])类中,我会收到此错误:error TS2094: The property 'navigator' does not exist on value of type 'RegisterViewControl'. this.navigator.navigate(HomeViewControl);
在类之外,语法不起作用。
我了解Javascript,但我是TypeScript的新手。有什么建议吗?
答案 0 :(得分:0)
您的RegisterViewControl
应该延长BaseViewControl
,在某种程度上,它应该延伸plat.ui.ViewControl
。 plat.ui.ViewControl
上有一个名为navigator
的属性。从您的错误来看,似乎RegisterViewControl
的定义方式可能有问题。
如果上述解决方案不起作用,您能提供整个RegisterViewControl文件的代码吗?
编辑:看起来你肯定是正确的。声明.d.ts
文件可能存在问题。尝试删除.tscache
文件夹,然后再次运行npm install
。它可能会给你更多有用的错误。
我们最近(如昨天)更新了框架和UI项目以部署不同的结构。您的public/typings/tsd.d.ts
可能会有以下参考:
/// <reference path="../../node_modules/platypus/platypus.d.ts" />
/// <reference path="../../node_modules/platypusui/platypusui.d.ts" />
仔细检查node_modules目录,您可能需要将tsd.d.ts
更改为以下内容:
/// <reference path="../../node_modules/platypus/dist/platypus.d.ts" />
/// <reference path="../../node_modules/platypusui/dist/platypusui.d.ts" />
如果是这种情况,您还应该进入public/common/css/main.less
文件并更改此行:
@import "../../../node_modules/platypusui/platypus";
到此:
@import "../../../node_modules/platypusui/dist/platypus";