ng-select

来源:互联网 发布:新日铁住金软件 地址 编辑:程序博客网 时间:2024/05/05 02:46

ng-select用来将数据同HTML<select>元素进行绑定。这个指令可以和ng-model以及ng-options指令一同使用,构建精细且表现优良的动态表单。

ng-options的值可以是一个内涵表达式(comprehension expression),其实这只是一种有趣的说法,简单来说就是它可以接受一个数组或对象,并对它们进行循环,将内部的内容提供给select标签内部的选项。它可以是下面两种形式。

数组作为数据源:

用数组中的值做标签;
用数组中的值作为选中的标签;
用数组中的值做标签组;
用数组中的值作为选中的标签组。

对象作为数据源:

用对象的键值(key-value)做标签;
用对象的键值作为选中的标签;
用对象的键值作为标签组;
用对象的键值作为选中的标签组。12

下面看一个ng-select指令的实例:

<div ng-controller="CityController">    <select ng-model="city"    ng-options="city.name for city in cities">

<option value="">Choose City</option>14</select>

    Best City: {{ city.name }}</div>
angular.module('myApp',[]).controller('CityController',function($scope) {
    $scope.cities = [      {name: 'Seattle'},      {name: 'San Francisco'},      {name: 'Chicago'},      {name: 'New York'},      {name: 'Boston'}

];});

15161718 

2 0
原创粉丝点击