簡體   English   中英

在中使用選定的值 <option> Angular.js

[英]Using a selected value in <option> Angular.js

我剛剛開始學習使用Angular.js,但我不知道這是什么:

我想顯示從陣列,其中所選擇的項value ="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指令。 option標簽中設置屬性value="{{song.id}}"這樣您的模型將包含選定的歌曲ID。

第二件事,您的循環顯示div和數組中的內容是錯誤的,因為在每個循環中,您將1傳遞給isSelected方法。 更好的是isSelected($index) 但是您不必執行此循環,只需使用包含數組中選定ID的模型即可

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

簽出

 <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM