AngularFire& ngOptions

时间:2014-05-20 04:11:45

标签: angularjs select firebase angularfire

我正在努力填充选择表单元素。这是我到目前为止的语法。它不会抓取program.title并填充ngOptions。

<select ng-model="student.program" ng-options="program.title for program in programList.title">
<option value="">Select A Program</option>
</select>

以下是我在Firebase上的数据的基本JSON结构:

{ "-JNIBeRDAuNN9c7SGZ91" : { "location" : "Online", "director" : "Shawn Clark", "title" : "Web Design & Development" }, "-JNIBuaQlWyEyWRjONPa" : { "location" : "Online", "director" : "Walen Morrow", "title" : "Graphic Design" }, "-JNIBmIwasMYOPRPupHl" : { "location" : "Campus", "director" : "Tracy Monohan", "title" : "Web Design & Development" }, "-JNKGPNj-lGzqHJ92RTD" : { "location" : "Online", "director" : "Glen Speedy", "title" : "Theory of Animation & Physics" }, "-JNK9oTO97PfSo-0wQfY" : { "location" : "Campus", "director" : "John Myers", "title" : "Instructional Design & Technology" }, "-JNIC3Tldo-Qi3ru2ph7" : { "location" : "Campus", "director" : "George Narrow", "title" : "Graphic Design" }, "-JNK8cdgdHKjH2meKl9x" : { "location" : "Online", "director" : "Stacy McNally", "title" : "Instructional Design & Technology" } }

2 个答案:

答案 0 :(得分:2)

我相信你在寻找

<select ng-model="student.program" ng-options="program.title for (id, program) in programList"><option value="">Select A Program</option></select>

您的JSON的根对象是一个对象,而不是一个数组。 See angular documentation for object data sources

See Plunker

答案 1 :(得分:-2)

请尝试以下代码。

应该有效:

<select ng-model="student.program" ng-options="program.title for program in programList"><option value="">Select A Program</option></select>

由于