0

我需要一些帮助来通过单击单选按钮来显示多个数据。

我的代码:html

<input type="radio" ng-model="opportunity" name="buy" value="buy">Buy
<input type="radio" ng-model="opportunity" name="services" value="services">Services
<input type="radio" ng-model="opportunity" name="social" value="social">Social

<div ng-show="isShown('buy')"> Test1 </div> // when radio button 1 is active
<div ng-show="isShown('services')"> Test2 </div> // when radio button 2 is active
<div ng-show="isShown('social')"> Test3 </div> // when radio button 3 is active

<div ng-show="isShown('buy')"> Test4 </div> // when radio button 1 is active
<div ng-show="isShown('services')"> Test5 </div> // when radio button 2 is active
<div ng-show="isShown('social')"> Test6 </div>// when radio button 3 is active

角J:

$scope.opportunity = '';

$scope.isShown = function(opportunity) {
return opportunity === $scope.opportunity;
};

当我运行此代码时,会显示 Test1 或 Test2 或 Test3。但是Test4、Test5、Test6不会显示。我怎么解决这个问题

4

1 回答 1

0

我在 plunker 中重新创建了您的代码: http ://plnkr.co/edit/xh4p9i1jpPl03bBH6K6P?p=preview

它工作得很好,所以我觉得你的最后 3 个 div 没有被控制器包裹

于 2014-03-03T10:30:38.080 回答