Modify select in AngularJS + Laravel

0

You want to change the search engine according to your category, this is the search engine in angular.js + Laravel:

<select id="selector-sectores" data-placeholder="+ AÑADIR CATEGORÍA" class="form-control"
   chosen="categorias" ng-model="categorias_seleccionadas" multiple=""
   ng-options="categoria.id as categoria.nombre for categoria in categorias.data"></select> 

This code modifies the entire file depending on the option chosen by the user. You want it not to be a select, but a list like this:

            <div class="menu-opciones">
                <ul>
                    <li><a href='' onclick=''>Cine</a></li>
                    <li><a href='' onclick=''>Restaurantes</a></li>
                    <li><a href='' onclick=''>Eventos</a></li>
                    <li><a href='' onclick=''>Tiendas</a></li>
                    <li><a href='' onclick=''>Noticias</a></li>
                    <li><a href='' onclick=''>Promociones</a></li>
                </ul>
            </div>

I have tried several things but I can not find the solution to make the list work, for example at the time an onclick was made, that the value of ng-model would be changed, the invisible selection would be done and everything would work without touching a lot of code but there's been no way

Can anyone think of a way to do it?

Greetings !!

    
asked by Guillermo Armando Alvarez 29.09.2017 в 11:58
source

1 answer

0

Try using the ngRepeat directive to print each element of the array. Then you assign the ngRepeat element to a function sending it the value per parameter and thus you will get the selected value:

angular.module("app",[])
.controller("ctrl", function($scope){
  $scope.model = {};
  $scope.model.items = [{text:"item1", value :1}, {text:"item2", value: 2}];
  
  $scope.model.setModel = function(item)
  {
     console.log(item);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="app" ng-controller="ctrl">
 <ul ng-repeat="item in model.items">
  <li ng-click="model.setModel(item)">{{item.text}}</li>
 </ul>
</div>
    
answered by 29.09.2017 / 14:41
source