何が間違っているのか分かりません。アプリケーションは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"}]
- 何トラブル?コンパイルされていないと出力されます 'ng-click =" deleteWorkspace(workspace.id) "'、どのようにする必要があります。 – dfsq
あなたの関数:renameWorkspace、deleteWorkspaceがあなたのサービスWorkspaceServiceにありますか? – NotBad4U
MainControllerの@ NotBad4U '$ scope.deleteWorkspace = function(workspaceId)' – Domin1992