如何从ng-repeat中分离元素以链接到另一个url?

时间:2017-04-14 07:55:20

标签: javascript html angularjs

我在angularjs中有html代码

<li ng-show="subCategory.status =='Active' || subCategory.status =='active'"
    ng-repeat="subCategory in subCategories">

    <a href="">
       <strong ng-click="addDetails(subCategory)">
           {{subCategory.subcategory}}
       </strong>
    </a> 

    <br>

</li>

subCategory in subCategoriesaddDetails(subCategory)函数内的网址相关联。

对于ng-repeat中的一个元素,我想链接到另一个单独的URL。 我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

如果您使用ui-router

    ui-sref=details({id:subCategory.subcategory})
配置

中的

    .state('details',{
                        url:'/details/:id',
                        templateUrl:'details.html'

得到它

myApp.controller('DetailController', ['$scope', '$stateParams', function($scope, $stateParams){
     $scope.message = "Your ID is " + $stateParams.id;

或者如果你使用ngroute

myApp.controller('DetailController', ['$scope', '$routeParams', function($scope, $routeParams){
     $scope.message = "Your ID is " + $routeParams.id;