111
rated 0 times
[
118]
[
7]
/ answers: 1 / hits: 25510
/ 13 Years ago, wed, february 22, 2012, 12:00:00
I want to create a simple list and when the user clicks on a button the value is displayed in a span element.
HTML & Controller
<html xmlns:ng=http://angularjs.org>
<script src=http://code.angularjs.org/angular-0.9.19.js ng:autobind></script>
<script type=text/javascript>
function MyController(){
this.list = [{name:Beatles, songs: [Yellow Submarine, Helter Skelter, Lucy in the Sky with Diamonds]}, {name:Rolling Stones, songs:[Ruby Tuesday, Satisfaction, Jumpin' Jack Flash] }]
this.songs = [];
}
</script>
<body ng:controller=MyController>
<p>selected: <span ng:bind=selected ng:init=selected='none' /></p>
<ul>
<li ng:repeat=artist in list>
<button ng:click=selected = artist.name >{{artist.name}}</button>
</li>
</ul>
<!--ol>
<li ng:repeat=song in songs>
{{song}}
</li>
</ol-->
</body>
I want to dynamically display the list of songs of the clicked artist. Is this the right approach?
More From » angularjs