Angularjs 单击<;时,ngRoute未更改视图;a>;标签

Angularjs 单击<;时,ngRoute未更改视图;a>;标签,angularjs,angular-ui-router,ngroute,route-provider,angularjs-ng-route,Angularjs,Angular Ui Router,Ngroute,Route Provider,Angularjs Ng Route,我是Angular JS新手,遇到了一个问题…我不知道发生了什么。请帮助解决它 我有索引文件,app.js已连接,app正在使用ngRoute…请参阅下面的代码 var app = angular.module('routedapp',['ngRoute']); //app.config("$routeProvider",function($routeProvider)) also tried this app.config(function($routeProvider) { $routeP

我是Angular JS新手,遇到了一个问题…我不知道发生了什么。请帮助解决它

我有索引文件,app.js已连接,app正在使用ngRoute…请参阅下面的代码

var app = angular.module('routedapp',['ngRoute']);
//app.config("$routeProvider",function($routeProvider)) also tried this

app.config(function($routeProvider) {
$routeProvider.when("/",{
    templateUrl: "views/home.html"
})
.when("/post",{
    templateUrl: "views/post.html"
})
.when("/contact",{
    templateUrl: "views/contact.html",
    controller: "contactCtrl"
})

})
app.controller('contactCtrl', function($scope){
$scope.lalteen = function(){
    console.log("clicked");
}

})
有4页。。。index.html、home.html、post.html和contact.html

//index.html代码

<html>
<head>
<title>Routed</title>

</head>
<body ng-app="routedapp" >
<div>welcome</div>
<div>
    <p ng-click="lalteen()">click me</p>
</div>

<!-- views here-->
<div ng-view >
</div>
    <script src="vendor/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-route.js"></script>
<script src="app.js"></script>
</body>
</html>

路由
欢迎
单击我

最初,加载index.html页面时,它会在视图中显示home.html内容,home.html有3个指向主页、帖子和联系人页面的链接……当我单击任何一个页面时……它不会更改视图,但会不断更改url,如:

http://localhost/route/#!/#%2F  //for home <a> tag
http://localhost/route/#!/#contact //for contact <a> tag and other like that.
http://localhost/route/#!/#%2F//用于家庭




我是新来的……请不要介意我的长篇大论……谢谢更新

好的,这样我就可以弄清楚你想做什么,以及为什么你的路线不起作用

首先还原更改,以便按照原始格式创建链接部分:

<div>This is post page</div>
<p><a href="#">Home<a/></p><br>
<p><a href="#post" ng-click="lalteen()">post</a></p><br>
<p><a href="#contact">contact</a></p><br>

为您创建了一个可用的plunker。

我从链接中删除了ng click and#但链接仍然没有导航到所需的模板…您可以创建plunker或其他什么吗?兄弟,请查看链接…您可以在inspect元素的网络中查看文件…抱歉,我不知道如何在plunker中添加我的代码…您做得很好。。。祝你在生活中也取得成功。。。阿门。。。请允许我问你最后一件事。。。我想从事编程(后端)。。。你能帮我选择合适的语言/领域吗?这些语言/领域的范围和收入都很好。。。
<div>This is post page</div>
<p><a href="#">Home<a/></p><br>
<p><a href="#post" ng-click="lalteen()">post</a></p><br>
<p><a href="#contact">contact</a></p><br>
 app.config(function($routeProvider, $locationProvider) {
   //note that this line does the magic ;)
   $locationProvider.hashPrefix('');
   //normal routing here
   $routeProvider.when("/",{
     templateUrl: "views/home.html"
   })
   .when("/post",{
     templateUrl: "views/post.html"
   })
   .when("/contact",{
     templateUrl: "views/contact.html",
     controller: "contactCtrl"
   })
 })