Angular 路由没有命中它的路由
Angular routing is not hitting its route
我是 angularjs 的新手,请帮我看看为什么我无法访问我的路由。问题是,当我点击联系人 link 时,它没有触发 .when
功能。
var app = angular.module('MyApp', ['ngRoute'])
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/Contact', {
templateUrl: '/ApiClient/Contact/AdminContact.html',
controller:'ContactCtrl'
})
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
hashPrefix:''
});
})
Html
<div>
<a href="#!/Contact">Contact</a>
</div>
应该是
<a href="#!Contact">Contact</a>
没有
<a href="#!/Contact">Contact</a>
你可以试试这个。
<p><a href="#/!">Main</a></p>
<a href="#!Contact">Contact</a> // Actually you put #!/Contact instead of #!Contact
<div ng-view></div>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/Contact", {
templateUrl: '/ApiClient/Contact/AdminContact.html',
controller:'ContactCtrl'
});
});
我是 angularjs 的新手,请帮我看看为什么我无法访问我的路由。问题是,当我点击联系人 link 时,它没有触发 .when
功能。
var app = angular.module('MyApp', ['ngRoute'])
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/Contact', {
templateUrl: '/ApiClient/Contact/AdminContact.html',
controller:'ContactCtrl'
})
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
hashPrefix:''
});
})
Html
<div>
<a href="#!/Contact">Contact</a>
</div>
应该是
<a href="#!Contact">Contact</a>
没有
<a href="#!/Contact">Contact</a>
你可以试试这个。
<p><a href="#/!">Main</a></p>
<a href="#!Contact">Contact</a> // Actually you put #!/Contact instead of #!Contact
<div ng-view></div>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/Contact", {
templateUrl: '/ApiClient/Contact/AdminContact.html',
controller:'ContactCtrl'
});
});