2017-03-23 29 views
0

我需要動態的數據與來自API調用採用NG-重複一系列單選按鈕」需要動態加載NG重複單選按鈕的內部NG-模型

我Controller負載NG-模型:

angular.module('app').controller('apiCallController', [$scope,'$http',function($scope,$http{ 

    $http.get(sampleUrl) 
    .success(function(data){ 
    $scope.sampleData = animal 
    }); 

}]); 

HTML:

<div class "row" ng-repeat="animal in animals"> 
    <div class="col-md-1> 
    <label class="radio-inline"> 
     <input type="radio" name="{{animal.Name}}" id="task1" value="true" ng-model="{{animal.ID}}"> 
     Yes 
    </label> 
    </div> 
    <div class="col-md-1> 
    <label class="radio-inline"> 
     <input type="radio" name="{{animal.Name}}" id="task1" value="false" ng-model="{{animal.ID}}"> 
     Yes 
    </label> 
    </div> 
</div> 

當我加載了現場,似乎一切正常顯示,但是當我檢查控制檯查看NG-模式的價值就顯示爲「而不是{{animal.ID}}「動物的價值。ID

不知道該怎麼辦。

+0

你的代碼看起來像是有語法錯誤,一些語義錯誤 - 嘗試'apiCallController',['$ scope',' –

+0

謝謝,修復它。 –

回答

0

您應該添加周圍的插值單引號:

<input type="radio" name="'{{animal.Name}}'" id="task1" value="true" ng-model="'{{animal.ID}}'"> 
+0

我試過了。它返回正確的ID,但是把它放在單引號和雙引號中,所以不是返回ng-model =「id值」,而是返回「'id'的值'」 –

0

你的代碼有

[$scope,'$http', 

你試圖注入一個變量$scope,但是當你使用依賴注入的這種格式,你需要提供一個字符串:

['$scope', '$http'