我的链接如下:
<a href="#/Home">view</a>
还有一个div来加载Home.html,如下所示:
<div class="col-md-8">
<ng-view></ng-view>
</div>
我的角度配置是:
myApp = angular.module("myApp", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider
.when("/Home", {
templateUrl: "Templates/Home.html",
controller: "HomeController"
})
})
.controller("BlogController", function ($scope, $http) {
$http.get("/Home/GetBlogEntries")
.then(function (response) {
$scope.data = response.data;
});
$scope.removeBlogEntry = function (index) {
$scope.data.Data.splice(index, 1);
};
})
.controller("HomeController", function ($scope, $http) {
});
在点击该链接之前,该网址显示为http://localhost:58679/#/Home
,点击后,地址栏转到http://localhost:58679/#!#%2FHome
基本上没有任何反应,我的home.html
没有被渲染到应有的位置。
答案 0 :(得分:0)
在您的配置中加入 $locationProvider.hashPrefix('');
。
myApp = angular.module("myApp", ["ngRoute"])
.config(function ($routeProvider,$locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider
.when("/Home", {
templateUrl: "Templates/Home.html",
controller: "HomeController"
})
})