「AngularJS入門」ng-optionsディレクティブのサンプル

書式
ラベル for 値 in 配列
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="kd" ng-controller="cftA">
<select ng-model="selectedName" ng-options="x for x in names">
</select>
</div>
<script>
var jj = angular.module('kd', []);
jj.controller('cftA', function($scope) {
$scope.names = ["メールアドレス", "ユーザ名", "住所","項目"];
});
</script>
<p>ng-optionsディレクティブを使用してドロップダウンリストに入力する方法</p>
</body>
</html>
<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body> <div ng-app="kd" ng-controller="cftA"> <select ng-model="selectedName" ng-options="x for x in names"> </select> </div> <script> var jj = angular.module('kd', []); jj.controller('cftA', function($scope) { $scope.names = ["メールアドレス", "ユーザ名", "住所","項目"]; }); </script> <p>ng-optionsディレクティブを使用してドロップダウンリストに入力する方法</p> </body> </html>
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="kd" ng-controller="cftA">

<select ng-model="selectedName" ng-options="x for x in names">
</select>

</div>

<script>
var jj = angular.module('kd', []);
jj.controller('cftA', function($scope) {
    $scope.names = ["メールアドレス", "ユーザ名", "住所","項目"];
});
</script>

<p>ng-optionsディレクティブを使用してドロップダウンリストに入力する方法</p>

</body>
</html>

 

AngularJS

Posted by arkgame