我不知道我在做什么错。应用正在通过REST从服务器获取对象,然后在表中列出该对象。一切看起来都不错,但是ngClick参数中的变量无法编译,因此会带来一些麻烦。

<tbody>
  <tr ng-repeat="workspace in workspaces" id="workspace_{[{workspace.id}]}">
    <td>{[{ workspace.name }]}</td>
    <td>
      <a href="javascript:void(0)" class="btn btn-info" ng-click="renameWorkspace(workspace.id)"><i class="fa fa-edit"></i></a>
      <a href="javascript:void(0)" class="btn btn-danger" ng-click="deleteWorkspace(workspace.id)"><i class="fa fa-trash-o"></i></a>
    </td>
  </tr>
</tbody>


输出:

<tbody>
  <tr ng-repeat="workspace in workspaces" id="workspace_1" class="ng-scope">
    <td class="ng-binding">Work12</td>
    <td>
      <a href="javascript:void(0)" class="btn btn-info" ng-click="renameWorkspace(workspace.id)"><i class="fa fa-edit"></i></a>
      <a href="javascript:void(0)" class="btn btn-danger" ng-click="deleteWorkspace(workspace.id)"><i class="fa fa-trash-o"></i></a>
    </td>
  </tr>
  <tr ng-repeat="workspace in workspaces" id="workspace_2" class="ng-scope">
    <td class="ng-binding">Private43243</td>
    <td>
      <a href="javascript:void(0)" class="btn btn-info" ng-click="renameWorkspace(workspace.id)"><i class="fa fa-edit"></i></a>
      <a href="javascript:void(0)" class="btn btn-danger" ng-click="deleteWorkspace(workspace.id)"><i class="fa fa-trash-o"></i></a>
    </td>
  </tr>
  <tr ng-repeat="workspace in workspaces" id="workspace_3" class="ng-scope">
    <td class="ng-binding">iuytre</td>
    <td>
      <a href="javascript:void(0)" class="btn btn-info" ng-click="renameWorkspace(workspace.id)"><i class="fa fa-edit"></i></a>
      <a href="javascript:void(0)" class="btn btn-danger" ng-click="deleteWorkspace(workspace.id)"><i class="fa fa-trash-o"></i></a>
    </td>
  </tr>
</tbody>


角度(1.5.5):

var cerber = angular.module('cerber', ['ngRoute', 'ngResource', 'ngCookies']);

cerber.config(function($routeProvider, $locationProvider, $interpolateProvider) {
  $interpolateProvider.startSymbol('{[{').endSymbol('}]}');

  $routeProvider
  .when('/', {
    templateUrl : templatesUrlPrefix + 'group',
    controller  : 'mainController'
  })
  [...]
  .otherwise({redirectTo : '/'});

  $locationProvider.html5Mode(false);
});

cerber.controller('mainController', function($scope, $cookies, $location, $http, $route, $compile, GroupService, InstanceService, WorkspaceService) {
$scope.manageWorkspaces = function(){
  $http({
    url: responsesUrlPrefix + 'get-workspaces',
    method: "GET",
    params: {}
  })
  .then(function(response){
    $scope.workspaces = response.data;
    angular.element('.workspaces-manage-modal').modal('show');
  });
}


响应:

[{"id":1,"name":"Work12","icon":"fa-briefcase","user_id":1,"created_at":"2016-05-16 21:01:22","updated_at":"2016-05-28 23:02:55"},{"id":2,"name":"Private43243","icon":"fa-user","user_id":1,"created_at":"2016-05-16 21:01:22","updated_at":"2016-05-28 23:02:08"},{"id":3,"name":"iuytre","icon":"fa-user","user_id":1,"created_at":"2016-05-28 23:51:23","updated_at":"2016-05-28 23:51:23"},{"id":4,"name":"iuytre","icon":"fa-user","user_id":1,"created_at":"2016-05-28 23:51:33","updated_at":"2016-05-28 23:51:33"}]

最佳答案

Angular JS不会向您显示在DOM中传递的参数,但会在控制器中提供正确的输出。

您可以轻松地在主控制器中编写函数,该函数接受以下参数:

$scope.renameWorkspace = function(workSpaceId){
    console.log(workSpaceId);
};

$scope.deleteWorkspace = function(workSpaceId){
    console.log(workSpaceId);
}

10-07 21:21