[英]Not understanding route
I took an AngularJS lesson. 我上了AngularJS课程。 But Angular is not understanding links to the details page, like template/1 if I click on a link from the browser. 但是,如果我单击浏览器中的链接,Angular不会理解到详细信息页面的链接,例如template / 1。 However, if I enter the URL in the address bar of the browser it works fine. 但是,如果我在浏览器的地址栏中输入URL,它将可以正常工作。 How can I resolve this? 我该如何解决?
App.js App.js
angular.module('templateStore.templates', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/templates', {
templateUrl: 'templates/templates.html',
controller: 'TemplatesCtrl'
})
.when('/template/:templateId', {
templateUrl: 'templates/template-details.html',
controller: 'TemplateDetailsCtrl'
})
.otherwise({
redirectTo: '/templates'
});
}])
.controller('TemplatesCtrl', ['$scope', function($scope) {
console.log('This is Template ');
}])
.controller('TemplateDetailsCtrl', ['$scope', '$http', function($scope, $http) {
console.log('This is Template Details');
}])
.controller('TemplateDetailsCtrl', ['$scope', '$http', function($scope, $http) {
console.log('This is Template Details');
}]);
Templates.html(main page) Templates.html(主页)
<div class="col-md-4 template">
<h3>Template 4</h3>
<img src="img/4.jpg">
<h4>$29.99</h4>
<a class="btn btn-primary btn-block" href="#/template/1">Details</a>
</div>
Attached is the image in which I highlighted the url in the address bar after clicking it 附件是单击后在地址栏中突出显示网址的图像
.when('/template/:templateId', {
templateUrl: 'templates/template-details.html',
controller: 'TemplateDetailsCtrl'
})
App.controller('TemplateDetailsCtrl', ['$scope', '$http',
'$routeParams', function($scope, $http, $routeParams) {
console.log($routeParams.templateId); }]);
Demo Yes you need #/template/2 and above its working code. 演示是的,您需要#/ template / 2及其以上的工作代码。 may this help you.... 可以帮助您...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.