条件ngRepeat基于下拉列表

时间:2015-09-27 22:27:45

标签: angularjs ng-repeat

我想根据下拉菜单中选择的项目显示一个列表。

当我使用下面的代码时,我收到此错误: public static bool IsWindowOpen<T>(string name = "") where T : Window { return string.IsNullOrEmpty(name) ? Application.Current.Windows.OfType<T>().Any() : Application.Current.Windows.OfType<T>().Any(w => w.Name.Equals(name)); } if (Helpers.IsWindowOpen<Window>("MyWindowName")) { // MyWindowName is open } if (Helpers.IsWindowOpen<MyCustomWindowType>()) { // There is a MyCustomWindowType window open } if (Helpers.IsWindowOpen<MyCustomWindowType>("CustomWindowName")) { // There is a MyCustomWindowType window named CustomWindowName open }

有关如何做到这一点的任何建议吗?

HTML:

TypeError: Cannot read property 'type' of undefined

控制器:

<select class="form-control" ng-model="editProject.project.type" 
ng-options="project as project.type for project in editProject.options track by project.type">
</select>

<ul class="list-group">
  <li class="list-group-item" ng-repeat="benefit in editProject.foods()">{{snack}}</li>
</ul>

1 个答案:

答案 0 :(得分:1)

你快到了。 select元素的ng-model与控制器中的条件不匹配。我还将benefit in editProject.foods()替换为snack in editProject.snacks()

<select class="form-control" ng-model="editProject.project" ng-options="project as project.type for project in editProject.options track by project.type"></select>
<ul class="list-group">
    <li class="list-group-item" ng-repeat="snack in editProject.snacks()">{{snack}}</li>
</ul>

由于在您选择项目之前未定义editProject.project,因此您必须在控制器中对其进行初始化:

editProject.project = {};

参见 fiddle