2016-07-22 57 views
0

我怎樣才能得到一個圖片ID我的控制器內而選擇圖像上我怎樣才能得到圖片ID我的控制器內,而在angularjs

我的HTML文件

<ul class="thumbnails"> 
    <li class="span3" ng-repeat="reward in rewardData.results"> 
    <a class="thumbnail" href="#"> 
     <img src="data:image/png;base64,{{reward.image}}" /> 
    </a> 
    </li> 
</ul> 
<div style="display:block;width:60%;"> 
    <a href="#invite" class="btn btn-theme invitefr" ng-click="selectPrizes()"> Save Challenge and Continue</a> 
</div> 

它會選擇圖像上顯示多個圖像,我想要一個圖像ID在我的控制器內,而一些人選擇任何圖像,任何人都可以知道如何實現它?

我的控制器:

app.controller("PrizesController", ["$location", "$scope","authenticationSvc","$http", function ($location, $scope,authenticationSvc, $http) { 
    console.log("inside prize controller"); 

    var token = authenticationSvc.getUserInfo(); 
    var config = { 
     headers: { 
      'h5cAuthToken': token.accessToken, 
      'Accept': 'application/json;odata=verbose' 
     } 
    }; 

    $http.get("http://IPandPortnumber/ccp-services/challengereward/allRewards", config) 
     .then(function (response) { 
      $scope.rewardData = response.data; 

     }); 

    $scope.selectPrizes = function() { 
     // some block of codes  
     $location.path("/invite"); 
    } 
}]); 
+0

裏面有元素名爲id或獎勵數據數組 –

+0

@Ranawaka,獎勵裏面獎勵數據 –

+0

@ ashishkumar-是否有唯一的圖像編號? – Maheshvirus

回答

0

試試這個控制器

$scope.imgId=''; 
    $scope.getImgId= function (id) { 
    console.log(id); 
    $scope.imgId=id; 
} 


    $scope.selectPrizes = function() { 
    // You will get selected img id here 
    console.log($scope.imgId); 
    $location.path("/invite"); 
} 
+0

謝謝@Mahesh Bhusanoor,因爲我是非常新的angularjs所以問這個愚蠢的問題,但希望這篇文章將有助於誰在angularjs中是新的。 –

1

傳遞圖像id來getImgId(reward.id)函數

<ul class="thumbnails"> 
    <li class="span3" ng-repeat="reward in rewardData.results"> 
    <a class="thumbnail" href="#"> 
    <img src="data:image/png;base64,{{reward.image}}" ng-click="getImgId(reward.id)"/> 
    </a> 
</li> 
</ul> 
<div style="display:block;width:60%;"> 
    <a href="#invite" class="btn btn-theme invitefr" ng- click="selectPrizes()"> Save Challenge and Continue</a> 
</div> 

    //inside controller 
    $scope.getImgId= function (id) { 
    console.log(id); 
} 
+0

「給一個男人一條魚,你喂他一個魚一天;教一個人釣魚,你給他一輩子的「 – Mistalis

+0

@Mistalis非常真實... – Maheshvirus