Angularjs ng重复由ng if在外部评估的值

Angularjs ng重复由ng if在外部评估的值,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,如何访问ng repeat指令范围之外的条件设置的ng repeat数据?例如,当有人选择在ng repeat内生成的单选按钮时,我想在ng repeat外显示一个div块 app.js var myApp = angular.module('myApp', []); function MyCtrl($scope) { $scope.obj = [{ condition: "Question1", status: "no" }, { condition: "Qu

如何访问ng repeat指令范围之外的条件设置的ng repeat数据?例如,当有人选择在ng repeat内生成的单选按钮时,我想在ng repeat外显示一个div块

app.js

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
  $scope.obj = [{
    condition: "Question1",
    status: "no"
  }, {
    condition: "Question2",
    status: "no"
  }];
}    

.html


{{o.condition}}
对
不
我出现了

我这里的东西在本地有效,但在js fiddle中尝试时就不行了-我不知道为什么

app.js(我习惯于这样定义控制器):

index.html(为
obj
中的每个
o
创建一个单独的
h1
):


问题:
地位
{{o.condition}}
对
不
问题{{$index}

我这里的东西在本地有效,但在js fiddle中尝试时就不行了-我不知道为什么

app.js(我习惯于这样定义控制器):

index.html(为
obj
中的每个
o
创建一个单独的
h1
):


问题:
地位
{{o.condition}}
对
不
问题{{$index}

这是不可能的。但是你可以试试这样的

添加功能,检查obj是否存在状态为“ok”的问题

html


这是不可能的。但是你可以试试这样的

添加功能,检查obj是否存在状态为“ok”的问题

html


您想根据哪个问题显示附加的
div
?是的,我想通过选择radio='Yes'来显示ng repeat之外的div(或任何元素)。谢谢您(可以)在
obj
中有多个问题
o
。哪个
yes
设置应显示附加div?或者,当设置为
yes
时,
obj
中的每个
o
都应该显示一个新的div?确切地说,想象一下如果用户选择了问题1;div将是div1,如果他们选择问题2、div2等。您想根据哪个问题显示附加的
div
?是的,我想通过选择收音机来显示ng外部的div(或任何元素)='Yes'。谢谢您(可以)在
obj
中有多个问题
o
。哪个
yes
设置应显示附加div?或者,当设置为
yes
时,
obj
中的每个
o
都应该显示一个新的div?确切地说,想象一下如果用户选择了问题1;这个div将是div1,如果他们选择问题2,div2,等等,这是非常好的,但我非常确定它可以做到。。。我在考虑ng if上的$watch函数,并从您的js示例中找到一个可能的解决方案。当您可以在Input上使用ng change调用函数时,为什么要使用watcher?这正是我所想的;我现在正在尝试这是非常好的,但我非常肯定它可以做到。。。我在考虑ng if上的$watch函数,并从您的js示例中找到一个可能的解决方案。当您可以在Input上使用ng change调用函数时,为什么要使用watcher?这正是我所想的;我现在正在试
<tr ng-repeat="o in obj">
  <td>{{o.condition}}</td>
  <td>
    Yes
    <input type="radio" ng-model="o.status" value="yes" /> No
    <input type="radio" ng-model="o.status" value="no" />
  </td>
</tr>

<!-- this will show based on an input event-->
<div ng-if="o.status == 'yes'" class="myClass">
I show up
</div>
var app = angular.module('myApp', []);

app.controller('MyCtrl', function($scope) {
  $scope.obj = [{
    condition: "Question0",
    status: "no"
  }, {
    condition: "Question1",
    status: "no"
  }];
});
<body ng-app="myApp">
  <div ng-controller="MyCtrl">

    <table>
      <thead>
        <th>Question</th>
        <th>Status</th>
      </thead>
      <tbody>
        <tr ng-repeat="o in obj">
          <td>{{o.condition}}</td>
          <td>
            Yes <input type="radio" ng-model="o.status" value="yes" />
            No <input type="radio" ng-model="o.status" value="no" />
          </td>
        </tr>
      </tbody>
    </table>

    <!-- this will display "question 0" and/or "question 1", based on input -->
    <div ng-repeat="o in obj">
      <h1 ng-if="obj[$index].status === 'yes'" class="myClass">
        question {{$index}}
      </h1>
    </div>

  </div>
  <script src="app.js"></script>
</body>
<div ng-if="someQuestionIsOk()" class="myClass">
$scope.someQuestionIsOk = function someQuestionIsOk() {

   for(var i = 0; i < $scope.obj.length; i++) {
       if($scope.obj[i].status == 'yes')
           return true;
   }

   return false;
}
<input type="radio" ng-model="o.status" ng-change="statusChange(o)" value="yes" />
 $scope.answerIsYes = false;

 $scope.statusChange = function statusChange(object) {
     if(object.status == 'yes')
         $scope.answerIsYes = true;
     else 
         $scope.answerIsYes = $scope.someQuestionIsOk();         
 }