I don't understand why I can't get this to work.
我不明白为什么我做不到。
I'll share the relevant code, let me know if you need to see more stuff.
我将分享相关代码,如果您需要了解更多信息,请告诉我。
Index.html
index . html
<div class="col-md-3"><a href="#/liberals">Liberals</a></div>
app.js
app.js
var app = angular.module('myApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider.
when("/liberals", {
templateUrl: "partials/liberals.html"
, controller: "LiberalsController"
});
});
app.controller('LiberalsController', function ($scope, $http) {
var url = "workingURL"; /// changed function to a simple string message to test
$scope.message = "Hello Liberals";
});
(partial view) liberals.html
liberals.html(局部视图)
<h1>Hello</h1>
{{message}}
PS: I'm not working on a political hate website for or against liberals!
PS:我不是在搞一个政治仇恨网站来支持或反对*主义者!
1 个解决方案
#1
2
As of AngularJS 1.6, the default value of the hashPrefix
has been changed to !
.
在AngularJS 1.6中,hashPrefix的默认值已经更改为!
There's two ways to get your routing to work with AngularJS 1.6+:
有两种方法可以让你的路由与AngularJS 1.6+一起工作:
- Add the hashprefix (
!
) to yourhref
's: - 将hashprefix(!)添加到您的href:
<a href="#!/liberals">Liberals</a>
< a href = " # ! /*主义者”>*派< / >
- Change (remove) the
hashPrefix
value using$locationProvider
: - 使用$locationProvider更改(移除)hashPrefix值:
$locationProvider.hashPrefix('');
locationProvider.hashPrefix美元(”);
I've created a working plunkr in which I used the second approach: https://plnkr.co/edit/oTB6OMNNe8kF5Drl75Wn?p=preview
我创建了一个工作柱塞,使用了第二种方法:https://plnkr.co/edit/otb6omnne8kf5drl75wn?
The commit regarding this breaking change can be found here
关于这一重大变化的承诺可以在这里找到
#1
2
As of AngularJS 1.6, the default value of the hashPrefix
has been changed to !
.
在AngularJS 1.6中,hashPrefix的默认值已经更改为!
There's two ways to get your routing to work with AngularJS 1.6+:
有两种方法可以让你的路由与AngularJS 1.6+一起工作:
- Add the hashprefix (
!
) to yourhref
's: - 将hashprefix(!)添加到您的href:
<a href="#!/liberals">Liberals</a>
< a href = " # ! /*主义者”>*派< / >
- Change (remove) the
hashPrefix
value using$locationProvider
: - 使用$locationProvider更改(移除)hashPrefix值:
$locationProvider.hashPrefix('');
locationProvider.hashPrefix美元(”);
I've created a working plunkr in which I used the second approach: https://plnkr.co/edit/oTB6OMNNe8kF5Drl75Wn?p=preview
我创建了一个工作柱塞,使用了第二种方法:https://plnkr.co/edit/otb6omnne8kf5drl75wn?
The commit regarding this breaking change can be found here
关于这一重大变化的承诺可以在这里找到