ng-click上ng模型值的变化

时间:2014-12-24 05:58:49

标签: angularjs angularjs-ng-click angularjs-ng-model

我有一个div,我在ng-repeat中有四个无线电选项,我的问题是当我点击按钮时,列表类的div应该重复并且ng-model应该改变让我们说它是否有价值'breakfast.favourite'点击后应该成为'breakfast.favourite1'为重复的div

<div class="main" ng-app="myApp" ng-controller="MyCtrl">    
<div class="list">
    <label class="item item-radio" ng-repeat="breakfastRecipe in breakfastRecipes" for="{{breakfastRecipe.name}}" ng-click="closeModal()">
        <input type="radio" ng-model="breakfast.favourite" ng-value="breakfastRecipe.name" id="{{'breakfast'+breakfastRecipe.id}}" name="boolean" />

    </label><br />
    {{breakfast.favourite}}
</div>
<button>Add Another</button>

这是我的控制器

var app = angular.module('myApp', []);
app.controller('MyCtrl', ['$scope', function ($scope) {
$scope.breakfastRecipes = [{id : 1, name : 'BreakfastRecipe1'},{id : 2, name : 'BreakfastRecipe2'},{id : 3, name : 'BreakfastRecipe3'},{id : 4, name : 'BreakfastRecipe4'}];
$scope.breakfast=[];
}]);

帮我解决这个问题

http://jsfiddle.net/hari_k/sjvrau3a/8/

1 个答案:

答案 0 :(得分:2)

你想要实现这个目标吗?

http://jsfiddle.net/TheRodeo/taujuuq2/3/

<button ng-click="addItem()">Add Another</button>
<div>
    <ul>
        <li ng-repeat="breakfastItem in breakfast  track by $index">{{breakfastItem}}</li>
    </ul>
</div>


$scope.addItem = function()
{
    $scope.breakfast.push($scope.breakfast.favourite);
}