angularjs - How to make this app multi-select? -


i want below angularjs code example here. "," should added after every color select. red,white,black

<!doctype html>  <html>  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>  <body>    <div ng-app="myapp" ng-controller="myctrl">    <p>select car:</p>    <select ng-model="selectedcar" ng-options="x.model x in cars">  </select>    <h1>you selected: {{selectedcar.model}}</h1>  <p>its color is: {{selectedcar.color}}</p>    </div>    <script>  var app = angular.module('myapp', []);  app.controller('myctrl', function($scope) {      $scope.cars = [          {model : "ford mustang", color : "red"},          {model : "fiat 500", color : "white"},          {model : "volvo xc90", color : "black"}      ];  });  </script>      </body>  </html>

selectbox 'one select'

use checkbox

    <!doctype html>      <html>      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>      <body>        <div ng-app="myapp" ng-controller="myctrl">        <p>select car:</p>        <span ng-repeat="x in cars">      <input type='checkbox' ng-model='x.checked'/>{{x.color}}      </span>        <h1>you selected: {{checkedmodels()}}</h1>      <p>its color is: {{checkedcolors()}}</p>        </div>        <script>      var app = angular.module('myapp', []);      app.controller('myctrl', function($scope , $filter) {          $scope.cars = [              {model : "ford mustang", color : "red"},              {model : "fiat 500", color : "white"},              {model : "volvo xc90", color : "black"}          ];            $scope.checkedcolors = function(){         var checkedarr = $filter('filter')($scope.cars, {checked : true});         var text = '';         for(var = 0 ; < checkedarr.length ; i++) {  if(text.length != 0){text += ','}  text += checkedarr[i].color;  }  return text;  }    $scope.checkedmodels = function(){         var checkedarr = $filter('filter')($scope.cars, {checked : true});         var text = '';         for(var = 0 ; < checkedarr.length ; i++) {  if(text.length != 0){text += ','}  text += checkedarr[i].model;  }  return text;  }          });      </script>          </body>      </html>

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -