Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在网站“无法读取未定义的属性”上获取错误_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 在网站“无法读取未定义的属性”上获取错误

Javascript 在网站“无法读取未定义的属性”上获取错误,javascript,angular,typescript,Javascript,Angular,Typescript,**尝试导航到图形/:id时出错。错误状态为无法读取undefined的属性。我试图在单击图形时显示图形上的详细信息,它应该从我的json文件中获取一个id来路由到页面 该错误似乎发生在getDrawingid:number函数或my drawingService服务中的某个位置。有人能看到我丢失的东西吗 从“@angular/platform browser”导入{BrowserModule}; 从“@angular/core”导入{NgModule}; 从'@angular/common/

**尝试导航到图形/:id时出错。错误状态为无法读取undefined的属性。我试图在单击图形时显示图形上的详细信息,它应该从我的json文件中获取一个id来路由到页面

该错误似乎发生在getDrawingid:number函数或my drawingService服务中的某个位置。有人能看到我丢失的东西吗

从“@angular/platform browser”导入{BrowserModule}; 从“@angular/core”导入{NgModule}; 从'@angular/common/http'导入{HttpClientModule}; 从“./app.component”导入{AppComponent}; 从“./drawings/drawing list.component”导入{DrawingListComponent}; 从'@angular/forms'导入{FormsModule}; 从“@angular/common”导入{CommonModule}; 从'@angular/router'导入{RouterModule}; 从“./home/home.component”导入{HomeComponent}; 从“./footer/footer.component”导入{FooterComponent}; 从“./favorite DrawingsComponent/favorite drawings.component”导入{FavoriteDrawingsComponent}; 从“./contacts/contacts.component”导入{ContactsComponent}; 从“./user/login.component”导入{LoginComponent}; 从“./DrawingDetails/drawing details/drawing details.component”导入{DrawingDetails组件} @NGD模块{ 声明:[ 应用组件, DrawingListComponent, HomeComponent, 页脚组件, FavoriteDrawingsComponent, 联系人组件, LoginComponent, DrawingDetails组件 ], 进口:[ 浏览器模块, HttpClientModule, FormsModule, 公共模块, RouterModule.forRoot[{path:'home',component:HomeComponent}, {路径:'drawings',组件:DrawingListComponent}, {path:'drawings/:id',component:DrawingDetailsComponent}, {path:'login',component:LoginComponent}, {路径:'*',组件:HomeComponent,路径匹配:'full'}, {路径:,组件:HomeComponent,路径匹配:'full'}] ], 提供者:[], 引导:[AppComponent] }
导出类AppModule{}噢,哇,我发现了这个问题,这是一个新手犯的错误。。所以代码很好。问题是JSON文件。在示例JSON文件中,我从以下内容获取数据:

{id:1, 名称:儿童化学, 描述:女孩正在和爸爸做化学实验。, imageUrl:of Two Books/GirlChemistry.jpg }

但是我的方法将id作为一个数字来查找,因此我只需删除JSON文件中每个图形对象上id属性的引号:

{id:1, 名称:儿童化学, 描述:女孩正在和爸爸做化学实验。, imageUrl:of Two Books/GirlChemistry.jpg }


现在页面加载良好,因为这些方法正在接收数字类型参数。感谢Igor和DEVCNN今天早上在这篇帖子上的快速回复。对于这篇文章中的任何问题以及我在这篇有点匆忙的文章中遗漏的任何细节,我深表歉意。我打算在帖子中添加JSON文件,这时我注意到了这个问题。。谢谢大家

嗨,David,你能不能不要把代码放在一个没有运行/没有显示错误的代码段中,因为这会让你很难阅读。有一种格式可以显示一些文本是代码,最好将其与一些标题一起使用,例如xyz.ts搜索错误消息:。如果您需要更多帮助,您需要包括所有错误详细信息,打开浏览器开发控制台并进行复制/粘贴,但请先阅读,如果需要,您可能可以自己解决。好的,非常感谢您提供的信息,George。很明显,我是新来的。该错误实际上没有显示在我构建并运行该网站,然后尝试导航到该网页中。绘图详细信息组件有一个输入错误。ngOnInit{let id=+this.route.snapshot.paramMap.get'id';//**删除'+'///this.drawingId=id;this.getDrawingid;}。请在浏览器上发布错误的屏幕截图。