【发布时间】:2017-01-25 17:04:42
【问题描述】:
我已经开始学习 Angularjs。我正在关注 w3schools 教程,我需要尝试一些东西。
在这里,我想根据我检查的单选按钮列出下拉列表。 (当我选择名称时,我只需要下拉列表中的名称,当我选择城市时,我只需要下拉列表中的城市等等)。
<body ng-app="myApp" ng-controller="myController">
<div>
<input type="radio" ng-model="selection" value="Name">Name
<input type="radio" ng-model="selection" value="Country">Country
<input type="radio" ng-model="selection" value="City">City
<br>
<div ng-switch="selection">
<div ng-switch-when="Name">
<ul>
<li ng-repeat="x in names">{{x.Name}}</li>
</ul>
</div>
<div ng-switch-when="Country">
<ul>
<li ng-repeat="x in names">{{x.Country}}</li>
</ul>
</div>
<div ng-switch-when="City">
<ul>
<li ng-repeat="x in names">{{x.City}}</li>
</ul>
</div>
</div>
<br>
<select ng-model="selectedName" ng-options="x.Name for x in names"></select>
</div>
</body>
这是 Angular 脚本文件。
var app = angular.module('myApp',[]);
app.controller('myController', function($scope,$http){
$http.get('http://www.w3schools.com/angular/customers.php')
.then(function(response){
$scope.names = response.data.records;
});
});
【问题讨论】:
标签: javascript angularjs json api