在angularjs中,点击一个链接后给下一页传递一个ID

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

本文关键字:一个 一页 ID 链接 angularjs      更新时间:2023-09-26

我有一个位置列表,我正在打印位置列表,其想法是当用户单击该位置时,它将用户带到另一个可以查看该位置详细信息的页面。我怎样才能做到这一点呢?

Page1 HTML:

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

:

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

在你的控制器中添加:inject $routeParams

$scope.id = $routeParams.id;
相关文章: