简体   繁体   English

TypeScript构建错误:“ IStateParamsService”类型不存在属性

[英]TypeScript Build Error : Property does not exist on type 'IStateParamsService'

I am using TypeScript almost entire of my client project. 我几乎在整个客户项目中都使用TypeScript。 Currently I am facing a technical problem. 目前,我面临一个技术问题。

In my HTML, I have an anchor tag like below : 在我的HTML中,我有一个如下所示的锚标记:

    <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. 在我的课程详细信息控制器中,我正在stateparam变量中获取值。 But if I want to access my 'courseId' from that variable, it is giving me build error. 但是,如果我想从该变量访问我的“ courseId”,则会给我生成错误。 Please check the image below. 请检查下面的图像。

带有构建错误的TypeScript代码

But if I remove the IF block, then I am getting the log in the developer console like below. 但是,如果我删除IF块,那么将在开发者控制台中获取日志,如下所示。

通过注释构建错误代码来控制台日志

I must get the course Id property and value to proceed. 我必须获取课程ID属性和值才能继续。 Otherwise I need to code this controller in pure angularjs which I don't want. 否则,我需要用我不想使用的纯angularjs编码此控制器。 Thanks. 谢谢。

Typescript prefers to work on maps explicitly through brackets notation []. Typescript倾向于通过方括号[]显式地处理地图。

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. 那应该解决您面临的直接问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打字稿类型错误属性不存在 - Typescript type error property does not exist 类型{}不存在Typescript属性 - Typescript property does not exist on type {} 类型 [] 打字稿上不存在属性 - property does not exist on type [] typescript 属性在类型上不存在-TypeScript - Property does not exist on type - TypeScript 打字稿错误:类型“元素”上不存在属性“包含”。 - Typescript error :Property 'contains' does not exist on type 'Element'.? "<i>TypeScript error: Property &#39;children&#39; does not exist on type &#39;{ children?: ReactNode;<\/i> TypeScript 错误:类型 &#39;{ children?: ReactNode; 上不存在属性 &#39;children&#39;<\/b> <i>}&#39;<\/i> }&#39;<\/b>" - TypeScript error: Property 'children' does not exist on type '{ children?: ReactNode; }' 如何修复 Typescript 中的“元素”类型错误不存在属性? - How to fix property does not exist on type 'Element' error in Typescript? Typescript 错误; 'CellDetails | 类型上不存在任何属性'按钮' 内容单元更新' - Typescript error; any Property 'button' does not exist on type 'CellDetails | ContentCellUpdate' 打字稿错误:类型{…}上不存在属性&#39;log&#39;-Console.log() - typescript error: Property 'log' does not exist on type {…} - Console.log() 打字稿错误:“Window”类型上不存在“_myApiUrl”属性 - Typescript error: Property '_myApiUrl' does not exist on type 'Window'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM