我对角度不是很熟悉,我只是无法弄清楚为什么我的代码表现得像这样..我有一个控制器,它从工厂获取数据和模态显示它。它根据它传递的id返回正确的数据,但是在ng-repeat之后它只加载第一条记录的数据或者没有任何内容:
`
<div ng-controller="TokensCtrl"><a href="#tokensModal" type="button" class="btn" data-toggle="modal" ng-click="getTokens(child.ChildId)" ng-model="child.ChildId">Get Tokens{{child.ChildId}}</a>
<div id="tokensModal" class="modal fade tokens" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Tokens:</h3>
</div>
<div class="modal-body">
<ul ng-repeat='token in tokens'>
<li><input value={{token}} /></li>
</ul>{{tokens}} <!--the first record set of tokens on every iteration -->
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
the controller, that returns the right data:
app.controller('TokensCtrl',
function ($scope, tokens) {
$scope.status;
$scope.test = 'testing';
$scope.getTokens = function (id) {
console.log(id + "controller");
tokens.getTokens(id)
.success(function (tokens) {
$scope.tokens = tokens;
console.log($scope.tokens);// here i can see it returns the right set of tokens
})
.error(function (error) {
$scope.status = "Unable to get tokens: " + error.message;
})
}
}
)
`
我认为这可能是一个愚蠢的错误,但我只是看不到它......或者不是
答案 0 :(得分:1)
尝试将ng-repeat指令放在 li 标记中,而不是 ul 。