本文实例讲述了AngularJS中下拉框的基本用法。分享给大家供大家参考,具体如下:
超文本标记语言正文:
div ng-app=' myApp ' ng-controller=' myCtrl ' select ng-model=' selected name ' ng-options=' x for x in name '/select等价于:选择选项ng-repeat=' item in name ' { item } }/option/select HR!重复绑定的值为一个字符串,ng-选项绑定的为一个对象-选择ng-model='选定的站点'选项ng-repeat='站点中的项目'值=' { { item。URL } } ' { { item。site } }/option/selectspan你选中的选址:{ {选定的站点} }/spanbr选择ng-model='选定的站点' ng-options=' x . site for x in sites '/select span你选中的选址:{{selectedSite}}/spanhr!-因为对象数组没有有角度的钥匙默认使用数组的下标值作为键显示-选择ng-model=' AAAA ' ng-options=' x for(x,y) in sites'/selectspan你选择的值是: { { AAAA } }/span/DivJavaScript操作代码:
var app=angular.module('myApp ',[]);app.controller('myCtrl ',函数($ scope){ $ scope。名称=['谷歌','百度','淘宝'];$ scope。sites=[{ site : ' Google ',url : 'http://www.google.com'},{site : 'Baidu ',url : 'http://www.baidu.com'},{ site : '淘宝,url : 'http://www。淘宝。com ' }];});效果:
更多关于AngularJS相关内容感兴趣的读者可查看本站专题: 《AngularJS指令操作技巧总结》 、 《AngularJS入门与进阶教程》 及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。