简体   繁体   English

如何在AngularJS中设置路由以正常工作

[英]How to set Routing in AngularJS to work properly

I have a problem with Routing in AngularJS. 我在AngularJS中遇到路由问题。 I use version 1.6.x and the latest version of angular.route.min.js file. 我使用版本1.6.x和最新版本的angular.route.min.js文件。

When I click the button which should take me to the other view, nothing happens. 当我单击应该将我带到其他视图的按钮时,什么也没有发生。 When searching for answer I found out that Routing in AngularJS doesn't work without node.js server. 当寻找答案时,我发现如果没有node.js服务器,AngularJS中的路由无法工作。 So I installed it and tried to run my application. 因此,我安装了它并尝试运行我的应用程序。

Here came the problem; 问题来了; I don't know how to launch this application on node.js. 我不知道如何在node.js上启动此应用程序。 In CMD on Windows I typed : "node index.html" and I got error. 在Windows上的CMD中,我输入:“ node index.html”,但出现错误。 The same is with "node app.js" - my javascript source code file. 我的javascript源代码文件“ node app.js”也是如此。

I attached screenshots to my source code. 我将屏幕截图附加到了源代码中。 If anyone could help me it would be great :-). 如果有人可以帮助我,那就太好了:-)。

Thanks in advance. 提前致谢。

My app.js source code. 我的app.js源代码。

My groceryList html file where I have a button to addItem.html view file. 我的食品杂货清单html文件,其中有一个按钮可以添加item.html视图文件。

Raj's comment seems right on. 拉吉的评论似乎正确。 You don't have a good screenshot of all of your code, but I think that you are missing the <div ng-view></div> aspect from your main view. 您没有完整的代码截图,但是我认为您在主视图中缺少<div ng-view></div>方面。

I made a plunker example out of your code to demonstrate: https://plnkr.co/edit/kB6ETz?p=preview 我用您的代码制作了一个简单的示例来演示: https ://plnkr.co/edit/kB6ETz?p=preview

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM