TypeScript 构建错误:类型“IStateParamsService"上不存在属性 [英] TypeScript Build Error : Property does not exist on type 'IStateParamsService'

查看:36
本文介绍了TypeScript 构建错误:类型“IStateParamsService"上不存在属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户项目几乎都在使用 TypeScript.目前我正面临一个技术问题.

在我的 HTML 中,我有一个如下所示的锚标记:

 

但是如果我删除 IF 块,那么我会在开发人员控制台中获取日志,如下所示.

我必须获得课程 ID 属性和值才能继续.否则我需要用我不想要的纯 angularjs 编写这个控制器.谢谢.

解决方案

Typescript 更喜欢通过括号表示法 [] 显式地处理地图.

如果你想从类似地图的对象中获取一个字段,你应该使用方括号而不是点表示法:

if (this.param['courseId'] === "00000....0000") {//.. 其余代码

这应该可以解决您面临的紧迫问题.

I am using TypeScript almost entire of my client project. Currently I am facing a technical problem.

In my HTML, I have an anchor tag like below :

    <a class="btn btn-default mrm" ui-sref="course-detail({courseId: '{{c.Id}}'})">Details</a>

In my course detail controller, I am getting the values in the stateparam variable. But if I want to access my 'courseId' from that variable, it is giving me build error. Please check the image below.

But if I remove the IF block, then I am getting the log in the developer console like below.

I must get the course Id property and value to proceed. Otherwise I need to code this controller in pure angularjs which I don't want. Thanks.

解决方案

Typescript prefers to work on maps explicitly through brackets notation [].

If you want to get a field out of a map-like object you should use square brackets instead of dot notation:

if (this.param['courseId'] === "00000....0000") {
  //.. rest of the code

That should solve the immediate issue you're facing.

这篇关于TypeScript 构建错误:类型“IStateParamsService"上不存在属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆