[英]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.
请检查下面的图像。
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.