繁体   English   中英

单击angularjs中的链接后将ID传递到下一页

[英]pass an ID to next page after clicking a link in angularjs

我有一个地点清单,我正在打印地点清单,其想法是,当用户单击该地点时,会将用户带到另一个可以查看该地点详细信息的页面。 我该如何实现?

HTML:第1页

<li ng-repeat="place in places.places">
    <a href="#/uncatdetails" ng-click="showplace(place.placeID)">{{place.name}}</a>
</li>

第2页:

<table ng-controller="UncatCtrl">
    <tr>
        <td>Name: </td><td>{{place.place.name}}</td>
    </tr>
    <tr>
        <td>placeID: </td><td ng-model="PlaceID">{{place.place.placeID}}</td>
    </tr>
</table>

角度:

myApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/uncatdetails', {
    templateUrl: 'templates/uncatpost.html',
    controller: 'UnCatPostCtrl'
    })
}])
.controller('UnCatPostCtrl', function ($scope, $http) {})

.controller('UncatCtrl', function ($scope, $http) {

$http.get('http://94.125.132.253:8000/getuncategorisedplaces').success(function (data, status, headers) {

    $scope.places = data;
    console.log(data);
    $scope.message = 'Uncategorised places';
})

$scope.showplace = function(placeID) {
  $http({method: 'GET', url: 'http://94.125.132.253:8000/getitemdata?ID=' + placeID}).
      success(function(data, status, headers, config) {
          $scope.place = data;               //set view model
          console.log(data);
          console.log(placeID);
           $scope.view = 'templates/detail.html';

      })
      .error(function(data, status, headers, config) {
          $scope.place = data || "Request failed";
          $scope.status = status;
          $scope.view = 'templates/detail.html';
      });
  }
})

试试吧

.when('/uncatdetails/:id', {templateUrl: 'ftemplates/uncatpost.html',
controller: 'UnCatPostCtrl'})

在您的HTML中

ng-href="uncatdetails/{{place.placeID}}"

在您的控制器中,添加此注入$ routeParams

$scope.id = $routeParams.id;

暂无
暂无

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

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