<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<h2>1.使用 ng-options 指令</h2>
<!--ng-options 指令创建的下拉列表,选中的值是一个对象, 所以建议使用 ng-option来创建select -->
<p>选择水果:</p>
<!-- ng-model 和 ng-init 里面绑定的变量名需要一样 -->
<select ng-model="selectedFruit" ng-init="selectedFruit= fruits[1]" ng-options="x.Alias for x in fruits">
</select>
<p>你选择的是: {
{selectedFruit.name}}</p>
<p>别名为: {
{selectedFruit.Alias}}</p>
<p>单价为: {
{selectedFruit.price}}</p>
<h2>2.使用 ng-repeat 指令</h2
angularJS- ng-options 和ng-repeat创建select
最新推荐文章于 2019-11-10 20:02:02 发布