1

何が間違っているのか分かりません。アプリケーションはREST経由でサーバからオブジェクトを取得して、それをテーブルに表示します。すべてがきれいに見えますが、ngClick引数の変数はコンパイルされないので、いくつか問題が発生します。ngRepeatの変数が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"}] 
+1

- 何トラブル?コンパイルされていないと出力されます 'ng-click =" deleteWorkspace(workspace.id) "'、どのようにする必要があります。 – dfsq

+0

あなたの関数:renameWorkspace、deleteWorkspaceがあなたのサービスWorkspaceServiceにありますか? – NotBad4U

+0

MainControllerの@ NotBad4U '$ scope.deleteWorkspace = function(workspaceId)' – Domin1992

答えて

0

角度JSあなたが渡している引数は表示されませんDOMの中であなたには右のoを与えるでしょうコントローラーのutput。

あなたは簡単として引数を受け入れ、あなたのメインコントローラ内の関数を書くことができます:*「ngClick引数の変数は、それが何らかのトラブルになりそうコンパイルされません」*

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

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

彼はすでに彼のMainCtrlにこれらの関数を書いています。 "MainControllerの@NotBad4U $ scope.deleteWorkspace = function(workspaceId" – NotBad4U

関連する問題