Tutorial 27 - Angularjs combobox example

Angularjs combobox example

This sample will help you know about using combobox via AngularJS. Ok we will answer two questions blow:

How to binding data to combobox?
How to get seclected value of combobox?




 <html>  
   <head>  
     <title>AngularJS combobox</title>  
     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>  
     <script>  
 var app = angular.module('myapp', []);  
 app.controller('ctrl', function($scope) {  
  $scope.months = ['January','February','March','April','May','June','July','August','September','October','November','December'];  
 });  
    </script>  
 <style>  
 body{background-color:#000; font-family: Arial, sans-serif;  
  color: #fff;}  
 .sample{width:400px;margin:0 auto; border:1px solid #aaa;padding:20px;margin-top:20px;}  
   </style>  
   </head>  
   <body ng-app="myapp">  
 <div class="sample" align="center" ng-controller="ctrl">  
  <h1>AngularJS Combobox sample</h1>  
 <select ng-model="selected" ng-options="opt as opt for opt in months" ng-init="selected=' September'"></select>  
  <h3>You have selected: {{selected}}</h3>  
 </div>   
   </body>  
  </html>  


No comments:

Post a Comment

Popular Posts