【问题标题】:Change of ng-model value on ng-click在 ng-click 上更改 ng-model 值
【发布时间】:2014-12-24 05:58:48
【问题描述】:

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

<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/

【问题讨论】:

  • 追加什么? ng-model 改成什么了?
  • 似乎工作正常,有什么问题?
  • 请在提问时提供更多详细信息。我们对您的项目一无所知。提供适当的问题陈述和预期行为

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


【解决方案1】:

您是否正在努力实现这一目标?

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);
}

【讨论】:

  • [upvoted] 虽然 OP 不接受它。它结束了我长期持续的头痛。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-15
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2015-10-05
  • 1970-01-01
  • 2015-12-23
相关资源
最近更新 更多