繁体   English   中英

不了解路线

[英]Not understanding route

我上了AngularJS课程。 但是,如果我单击浏览器中的链接,Angular不会理解到详细信息页面的链接,例如template / 1。 但是,如果我在浏览器的地址栏中输入URL,它将可以正常工作。 我该如何解决?

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(主页)

<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>

附件是单击后在地址栏中突出显示网址的图像

.when('/template/:templateId', {
             templateUrl: 'templates/template-details.html',
              controller: 'TemplateDetailsCtrl'
             })  

 App.controller('TemplateDetailsCtrl', ['$scope', '$http',
'$routeParams', function($scope, $http, $routeParams) {        
     console.log($routeParams.templateId); }]);

演示是的,您需要#/ template / 2及其以上的工作代码。 可以帮助您...

理解

[英]Understanding <a href=“#!”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM