在Platypi中放置ViewControl的注册函数的地方

我一直在浏览[Platypi.io/docs/getting-started/] [1],但是却一直停留在有关添加函数的部分,以允许用户注册演示应用程序( https://platypi.io/docs/入门/允许用户注册 )

具体步骤是

现在,我们添加我们的注册function。 只要点击或点击平台button,该function将被触发。 在模板中,我们通过指定plat-tap属性中的函数来定义button的轻击事件。 函数名是registry,所以当点击这个button时,注册函数将会在我们的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; }); } 

我在哪里添加这个function? 如果我把它放在RegisterViewControl(像[this] [2])类,我得到这个错误: error TS2094: The property 'navigator' does not exist on value of type 'RegisterViewControl'. this.navigator.navigate(HomeViewControl); error TS2094: The property 'navigator' does not exist on value of type 'RegisterViewControl'. this.navigator.navigate(HomeViewControl); 在课堂之外,语法不起作用。

我知道我的方式围绕Javascript,但是对于TypeScript来说是新的。 有什么build议么?

你的RegisterViewControl应该扩展BaseViewControl ,并且在某个级别上应该扩展plat.ui.ViewControlplat.ui.ViewControl有一个名为navigator的属性。 从你的错误,它看起来像RegisterViewControl是如何定义错误的。

如果上述解决scheme不起作用,您能否提供整个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";