$scope.results = [
{id: 1, text: 'a'},
{id: 2, text: 'b'},
{id: 3, text: 'c'},
{id: 4, text: 'd'}
];
<label ng-repeat="result in results">
<input type="checkbox" name="res" data-checklist-model="my.resid" data-checklist-value="result.id" ng-click="myFunction(result.id)" > {{result.text}}
</label>
$scope.myFunction = function(id){
$scope.dflt = [];
if($scope.my.resid == 1){
$scope.dflt.push({"id": 1, "text": 'a'});
console.log($scope.dflt);
}
}
我要动态地添加如我所料下面的结果,但现在它只是显示[{"id":1,"text":"a"}]
追加动态重视到数组angularjs
[{"id":1,"text":"a"}, {"id":2,"text":"b"}, {"id":3,"text":"c"}, {"id":4,"text":"d"}]
在每一次点击,'$ scope.dflt'再次初始化时间......使它在全球控制器... – Rayon