Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Angular.js中使用选定值_Javascript_Arrays_Angularjs_Angularjs Ng Repeat_Angularjs Ng Model - Fatal编程技术网

Javascript 在Angular.js中使用选定值

Javascript 在Angular.js中使用选定值,javascript,arrays,angularjs,angularjs-ng-repeat,angularjs-ng-model,Javascript,Arrays,Angularjs,Angularjs Ng Repeat,Angularjs Ng Model,我刚刚开始学习如何使用Angular.js,但我无法理解这一点: 我想显示所选值=song.title与数组中的song.title匹配的数组中的项目 这是我的密码 <select> <option ng-repeat="song in songs.tracks">{{song.title}}</option> </select> 现在,我想在此显示更多选定歌曲阵列: <section ng-repeat="song in son

我刚刚开始学习如何使用Angular.js,但我无法理解这一点:

我想显示所选值=song.title与数组中的song.title匹配的数组中的项目

这是我的密码

<select>
     <option ng-repeat="song in songs.tracks">{{song.title}}</option>
</select>
现在,我想在此显示更多选定歌曲阵列:

<section ng-repeat="song in songs.tracks">
     <div class="panel" ng-show="panel.isSelected(1)" >

<!-- in here i wanna show stuff from the array of the selected song -->

     </div>

所以,首先,您必须将模型附加到select标记,使用ng model指令执行此操作。在选项标记集属性值={{song.id}}中,您的模型将包含选定的歌曲id

第二件事,使用数组中的内容显示div的循环是错误的,因为在每个循环中,您都将1传递给isSelected方法。更好的是ISS指数。但你不必做这个循环,只需使用你的模型在歌曲数组中包含选定的id

<div>{{songs[yourmodel].title}}</div>
结帐


谢谢!我还没有遇到ng选项表达式,你能解释一下它是如何工作的吗?你知道我需要在什么条件下单击一个按钮,以便在单击时显示“歌曲”数组中的第一个项目吗?
 <div>
  Select Song :: <select ng-model="selectedSong" ng-options="song as song.title for song in songs.tracks">
  </select>

  </div>
  <div>
  Selected Song :: 

  {{selectedSong}}
  </div>