angularjs - condition for ng-model -


help me please ng-model. have input field when selecting substituted values array 'posters'. yhe value selected filter appear in list. list displayed default 'the grund tour'. when enter in form of value not in array - in list displays empty field, need displayed or value of array or default value (if form entered value not of array). have no idea how it. think may possible apply condition ng-model make work values of array

my code html:

<div class="container" ng-controller = "formcontroller">     <div class="container__item container__form"><!-- 1 -->         <form action="" class="form">             <input type="text" class="form__input" placeholder="search..." autocomplete="on" list="posters" ng-model="postertitle"  >             <datalist id="posters" >                 <option ng-repeat="poster in posters" >{{poster.title}}                 </option>             </datalist>          </form>              </div>     <div class="container__item container__list"><!-- 2 -->          <ul class="list" id="item">             <li class="list__item" ng-if="poster.title =='the grand tour'" ng-repeat="poster in posters | filter:postertitle"><i class="fa fa-rocket list__fa" aria-hidden="true"></i>{{poster.title}}</li>             <li class="list__item" ng-if="poster.title!='the grand tour'" ng-repeat="poster in posters | filter:{title:postertitle}">{{poster.title}}</li>         </ul>     </div>       </div> 

controller:

'use strict';   angular.module('oldmentest')    .controller('formcontroller', ['$scope', 'postersname', function($scope, postersname) {     $scope.posters= postersname.getposters();      $scope.postertitle = '';  }]); 

var:

'use strict';  angular.module('oldmentest')  .service('postersname', function() {  var posters = [{     title: 'var1',     description: 'lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua.',     image: 'resources/images/mars.jpg' }, {     title: 'var2',     description: 'tlorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua.',     image: 'resources/images/earth.jpg' }, {     title: 'var3',     description: 'lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua.',     image: 'resources/images/venus.jpg' } ];  this.getposters = function(){     return posters; };  }); 

thanks hepl!

as understand have apply filter conditionally on specific property or properties based on title.

you below.

<li class="list__item"   ng-init="poster.filter = (poster.title =='the grand tour' ? {filter: postertitle }: postertitle"   ng-repeat="poster in posters | filter: poster.filter">       <i ng-if="poster.title =='the grand tour'" class="fa fa-rocket list__fa" aria-hidden="true"></i>.       {{poster.title}}  </li> 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -