Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 提交投票并使用Angular锁定_Angularjs - Fatal编程技术网

Angularjs 提交投票并使用Angular锁定

Angularjs 提交投票并使用Angular锁定,angularjs,Angularjs,我有以下内容来显示图像列表(使用角度): 然后它工作了 我检查了图像。Id等于2。知道它为什么不起作用吗 我不知道如何使用参数创建路径。添加ng单击链接 <div class="overlay"> <a ng-click="vote(image)" href="#">VOTE</a> <span>{{image.Votes}}</span> <a ng-click="lock(image)" h

我有以下内容来显示图像列表(使用角度):

然后它工作了

我检查了图像。Id等于2。知道它为什么不起作用吗


我不知道如何使用参数创建路径。

添加ng单击链接

<div class="overlay">
      <a ng-click="vote(image)" href="#">VOTE</a>
      <span>{{image.Votes}}</span>
      <a ng-click="lock(image)" href="#">LOCK</a>
    </div>

还要尽量避免控制器内部的http`调用。通过使用角度服务进行抽象。看看约翰·帕帕的,推荐这个还不够

拥有服务将是下一步。。。我只是从angular开始,所以首先我需要做这项工作。当使用image.Id调用操作时,我仍然有一个问题。知道为什么吗?我刚刚用您的代码添加了一个更新…您确定您的对象上有image.Id吗(在调用
$http
之前执行
console.log(image)
?您也可以查看网络选项卡,查看正在发布到该服务的url。我发现了问题。我希望使用Int作为Id,并传递一个字符串。
    <div class="overlay">
      <a ng-click="vote(image)" href="#">VOTE</a>
      <span>{{image.Votes}}</span>
    </div>

    $scope.vote = function (image) {

      $http.post('api/images/' + image.Id + '/vote', { id: image.Id }).
        success(function (data, status, headers, config) {
          alert("success");
        }).
        error(function (data, status, headers, config) {
          alert(data);
          alert(status);
        });

    };
    $http.post('api/images/2/vote', { id: image.Id }).
<div class="overlay">
      <a ng-click="vote(image)" href="#">VOTE</a>
      <span>{{image.Votes}}</span>
      <a ng-click="lock(image)" href="#">LOCK</a>
    </div>
application.controller('ImageController', function ImageController($scope, $http) {
    $scope.vote = function (image) {
        // image.id is available here
    };

    $scope.lock = function (image) {
        // image.id is available here
    };

    $http.get('api/images').
      success(function (data, status, headers, config) {
        $scope.images = data;
      }).
      error(function (data, status, headers, config) {
      });

  });