Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 特定url的角度路由_Javascript_Angularjs_Routes - Fatal编程技术网

Javascript 特定url的角度路由

Javascript 特定url的角度路由,javascript,angularjs,routes,Javascript,Angularjs,Routes,我目前正在进行一个MEAN stack项目,并试图获得一个特定的模板,以显示在特定的url上 当前,如果用户转到www.myurl/catalog,它将加载catalog.html模板,就像加载任何/catalog?catagory=productType url一样 我希望这样,当用户转到/catalog?category=specificProductType时,它将加载catalogSpecific.html模板。目前,catalog.html模板取代catalogSpecific.htm

我目前正在进行一个MEAN stack项目,并试图获得一个特定的模板,以显示在特定的url上

当前,如果用户转到www.myurl/catalog,它将加载catalog.html模板,就像加载任何/catalog?catagory=productType url一样

我希望这样,当用户转到/catalog?category=specificProductType时,它将加载catalogSpecific.html模板。目前,catalog.html模板取代catalogSpecific.html模板。我找不到关于这个具体问题的太多信息,因此任何帮助都将不胜感激

目前我的路线如下所示:

app/front/app.js

angular.module('app', ['ngRoute',
                    'app.LandingModule.controller',
                    'app.CatalogModule.controller',
                    'app.ProductModule.controller',
                    'app.HeaderModule.directives',
                    'app.FooterModule.directives'
                    ])


.config(['$routeProvider', function($routeProvider) {
  $routeProvider
.when('/', {
  templateUrl: 'html/landing.html',
  controller: 'LandingController'
})
.when('/catalog', {
  templateUrl: 'html/catalog.html',
  controller: 'CatalogController'
})
.when('/catalog?category=specificProductType', {
  templateUrl: 'html/catalogSpecific.html',
  controller: 'CatalogController'
})
.otherwise({
  redirectTo: '/'
});
}]);

编辑:看来我错了,默认路由器不可能做到这一点。正如Hadi在他们的评论中所描述的,您可以用一个函数替换“templateUrl”,该函数返回给定当前路由的模板url


据我所知,你不能路由的方式,你想与内置角路由器

据我所知,您有两种选择:

1:学习使用ui路由器库(可在此处找到:)


2:将/catolog中的所有路由发送到一个控制器/页面,该控制器/页面手动查看您的路由参数,并根据该参数手动重新路由。(请参阅$routeParams)

编辑:似乎我错了,因为默认路由器无法实现这一点。正如Hadi在他们的评论中所描述的,您可以用一个函数替换“templateUrl”,该函数返回给定当前路由的模板url


据我所知,你不能路由的方式,你想与内置角路由器

据我所知,您有两种选择:

1:学习使用ui路由器库(可在此处找到:)


2:将/catolog中的所有路由发送到一个控制器/页面,该控制器/页面手动查看您的路由参数,并根据该参数手动重新路由。(请参阅$routeParams)

尝试使用
模板URL
这样的函数。我还没有测试

  templateUrl: function($location){
     if($location.category)
         return 'html/catalogSpecific.html';
       else
          return  'html/catalog.html'; 
 },

尝试使用
模板URL
这样的函数。我还没有测试

  templateUrl: function($location){
     if($location.category)
         return 'html/catalogSpecific.html';
       else
          return  'html/catalog.html'; 
 },

我通过哈迪的例子找到了答案:

    .when('/catalog', {
  templateUrl: function($location){
            if($location.category == "specificProductType") {
            return 'html/catalogSpecific.html';         
        } else {
            return 'html/catalog.html';
       }
},
  controller: 'CatalogController'
})

我能够按照哈迪的例子来理解这一点:

    .when('/catalog', {
  templateUrl: function($location){
            if($location.category == "specificProductType") {
            return 'html/catalogSpecific.html';         
        } else {
            return 'html/catalog.html';
       }
},
  controller: 'CatalogController'
})

我尝试了以下方法:如果($location.search().category=“specificProductType”)我也尝试过咯咯笑:如果($location.search().category==“specificProductType”)运气不好,它只是破坏了我的应用程序。我认为这是正确的方向,但很明显我还是做错了什么(这是我第一次使用angular)嘿,哈迪,我检查了你的答案,但看起来没有什么不同。我正在尝试匹配category=诸如此类后面的字符串/catalog?category=specificProductType将引导我找到我的特定模板,而所有其他类别,/catalog?category=specificProductType#2,/catalog?category=specificProductType#3等等将引导我找到通用类别模板。嘿,哈迪,我能够按照您的示例解决这个问题。最后我得到了.when('/catalog',{templateUrl:function($location){if($location.category==“specificProductType”){return'html/catalogSpecific.html';}else{return'html/catalog.html';},controller:'CatalogController'})这只是一个展示如何做的示例。请看,我在我的路线中尝试了以下方法:如果($location.search().category=“specificProductType”),我也尝试过咯咯笑:如果($location.search().category==“specificProductType”)运气不好,它只是破坏了我的应用程序。我认为这是正确的方向,但很明显我还是做错了什么(这是我第一次使用angular)嘿,哈迪,我检查了你的答案,但看起来没有什么不同。我正在尝试匹配category=诸如此类后面的字符串/catalog?category=specificProductType将引导我找到我的特定模板,而所有其他类别,/catalog?category=specificProductType#2,/catalog?category=specificProductType#3等等将引导我找到通用类别模板。嘿,哈迪,我能够按照您的示例解决这个问题。最后我得到了.when('/catalog',{templateUrl:function($location){if($location.category==“specificProductType”){return'html/catalogSpecific.html';}else{return'html/catalog.html';},controller:'CatalogController'})这只是一个展示如何做的示例。我尝试了Hadi的建议,但没有成功,我将查看您的链接。谢谢我尝试了哈迪的建议,但没有成功,我会看看你的链接。谢谢