I want to perform a search on json and display it on screen
Check out this plunk i made.Can someone tell me how can i perform a search and display on screen and use that data .
<div class="list list-inset">
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search">
</label>
</div>
I forked your plunker here but in case you don't get it you need to add ng-model in your search bar so change this line to
<input type="text" placeholder="Search" ng-model='query'>
And then in your ng-repeat do:
<article ng-repeat="object in yifito | filter : query">
And it works, I just checked (and forked)
Add ng-model to the input field and filter the ng-repeat using the function
<ion-content>
<div class="list list-inset">
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search" ng-model="search">
</label>
</div>
<section class="list">
<article ng-repeat="object in yifito|filter:myfilter ">
<a href="{{object.url}}" target="_system" onclick="window.open('{{object.url}}',_system,'location=yes')" class="item">
<img ng-src="{{object.medium_cover_image}}">
<h2 class="noWhiteSpace">{{object.title}}</h2>
<p class="noWhiteSpace">{{object.genres}}</p>
<p class="noWhiteSpace">Year {{object.year}} Rating {{object.rating}}</p>
</div>
</a>
</article>
</section>
</ion-content>
Myfilter function logic in js file
$scope.myfilter = function(obj) {
var val = true;
if($scope.search && !obj.title ||
$scope.search && !obj.Rating ||
$scope.search && !obj.year
) {
val = false;
}
return val;
}
Related
<form class="form-inline" name="form" novalidate>
<div class="sub-form" ng-form is-active ng-init="active = true" name="info">
<div class="col-md-4 col-sm-6 col-ie-4">
<div class="select-input">
<label for="xyz">Xyz *</label>
<i class="fa fa-check-circle success" ng-show="form.info.xyz.$valid"></i>
<i class="fa fa-spinner fa-spin"></i>
<i class="fa fa-times-circle error" ng-show="(form.info.xyz.$invalid && !form.info.xyz.$pristine)"></i>
<div class="styled-select">
<select
heights
name="xyz"
id="xyz"
ng-options="xyz.in as xyz.ft for xyz in xyzs"
ng-model="player.xyz"
required>
<option value="" selected="selected">-- Select --</option>
</select>
</div>
</div>
</div>
</div>
</form>
<div class="back-next-button-row">
<div class="red-button tiny-button next-button" ng-if="form.$valid">
<button ng-click="next()"><span class="button-text">Next</span><i class="fa fa-chevron-right"></i></button>
</div>
<div class="red-button tiny-button next-button" ng-if="form.$invalid">
<button ng-click="error()"><span class="button-text">Error</span><i class="fa fa-chevron-right"></i></button>
</div>
</div><!--back-next-button-row-->
In Script
$scope.form = {};
$scope.form.info = {};
$scope.formError = function () {
console.log($scope.form.info.xyz);
//Getting Object {}
}
While in html its showing proper objects that i expect
Basically I would like to check
if($scope.form.info.xyz.$invalid){
alert("Invlid")
}
I would be thankful if I came to know why this is creating problem in this prospect
With angular, you can do this inside the HTML and dont have to carry it to the script. If you want to check any form element is invalid or incomplete, you can add an element like this.
<p class="text-danger" ng-show="form.$invalid">Invalid</p>
If you still want to do on click, try the below.
In the HTML capture the form name on your function.
<button ng-click="next('form')">Validate</button>
In JS, you can have a function like the below,
$scope.next = function(form){
if ($scope[form].$valid) {
alert("True");
} else {
alert("Invalid");
}
};
I'm getting some posts to my ionic app via JSON data , and I'm filetering the posts receipts with a searchbar input , the problem that the search bar input and the filetered results are showing in the same page , I want to show the result in another page , and the first page will be only for the search bar .
(I added the new page and I'll add a button for the search page
)
This is my code :
<label class="item item-input">
<input type="text" placeholder="Nom du Jneyne" ng-model="nom" ng-
change="showSelectValue(nom)">
</label>
<ion-item class="item item-thumbnail-left item-text-wrap item-icon-right"
ng-repeat="post in (filteredItems = ( recent_posts
| filter:{title:nom} " href="#/main/postDetail/{{post.id}}">
<img ng-src="{{post.thumbnail}}" />
<h2>{{post.title}}</h2>
<p ng-bind-html="post.excerpt" </p>
<ion-option-button class="button-dark">
<i class="icon ion-heart"></i>
</ion-option-button>
</ion-item>
</ion-list>
try adding ng-if and change code as
<label class="item item-input" ng-if="srhItem">
<input type="text" placeholder="Nom du Jneyne" ng-model="nom" >
<input type ="submit" value="search" ng-click="showSelectValue(nom)">
</label>
and your display part to
<div ng-if = displayResult>
<ion-item class="item item-thumbnail-left item-text-wrap item-icon-right"
ng-repeat="post in (filteredItems = ( recent_posts
| filter:{title:nom} " href="#/main/postDetail/{{post.id}}">
<img ng-src="{{post.thumbnail}}" />
<h2>{{post.title}}</h2>
<p ng-bind-html="post.excerpt" </p>
<ion-option-button class="button-dark">
<i class="icon ion-heart"></i>
</ion-option-button>
</ion-item>
</div>
and add $scope.srhItem = false,$scope.displayResult = true in your showSelectValue() function.and dont forget to add $scope.srhItem = true at the beginning of your controller
I'm building a form using Angular 1.1.1 and Ionic.
There are many "wallets" and the user needs to send a new "value" to each of the wallet. My form has a validation for all fields which works fine when the 'submit' button for the form is pressed.
However, I also have a button next to each wallet to send only value to this wallet (not different values to all wallets). When I press it, all the validation errors appear, but I need error to be visible only for the particular wallet.
My form (index.html):
<form name="myForm" ng-submit="sendValues(wallets)" ng-controller="valuesCtrl" novalidate>
<div class="row" ng-repeat="wallet in wallets">
<div class="col item item-input-inset">
<label class="item-input-wrapper item-text-wrap">
<input name="wallet_{{wallet.id}}" type="number" ng-model="wallet.value" type="text" required/>
</label>
<span ng-show="myForm.wallet_{{wallet.id}}.$error.required">!!!</span>
</div>
<div class="col item">{{ wallet.previous }}</div>
<button ng-click="sendValue(wallet)">
<i class="ion-android-send"></i>
</button>
<span class=ng-show="myForm.$submitted==true && myForm.wallet_{{wallet.id}}.$error.required">Required</span>
</div>
<button class="button" type="submit">Submit</button>
</form>
My controller (values.js):
'Use Strict';
angular.module('App')
.controller('valuesCtrl', function($scope, $localStorage, UserService, $state) {
$scope.sendValues = function(wallets){
if ($scope.myForm.$valid) {
...
} else {
$scope.myForm.submitted = true;
}
},
$scope.sendValue = function(wallet){
if (wallet.value == null) {
$scope.myForm.submitted = true;
} else {
...
}
}
})
You need to create a form for each wallet
This is due to your html name attributes has same value inside ng-repeat
Use $index in your name field for differentiate all the name attribute.
<form name="myForm" ng-submit="sendValues(wallets)" ng-controller="valuesCtrl" novalidate>
<div class="row" ng-repeat="wallet in wallets">
<div class="col item item-input-inset">
<label class="item-input-wrapper item-text-wrap">
<input name="wallet_{{$index}}" type="number" ng-model="wallet.value" type="text" required/>
</label>
<span ng-show="myForm.wallet_{{wallet.id}}.$error.required">!!!</span>
</div>
<div class="col item">{{ wallet.previous }}</div>
<button ng-click="sendValue(wallet)">
<i class="ion-android-send"></i>
</button>
<span class=ng-show="myForm.$submitted==true && myForm.wallet_{{$index}}.$error.required">Required</span>
</div>
<button class="button" type="submit">Submit</button>
</form>
You have to create a form inside form again. But as per HTML standard you can not have nested form. But angular provided that ability to have nested form but the inner form should be ng-form. Which mean you are going to wrap form & inside that you can find multiple ng-form's.
So you should have ng-form="innerForm" which will keep track of each repeated form.
Other thing which I observed is, you did mistake while using ng-show(you had {{}} inside ng-show expression, which would not work). To fix it you could access object via its key like ng-show="innerForm['wallet_'+wallet.id].$error.required"
Markup
<form name="myForm" ng-submit="sendValues(wallets)" ng-controller="valuesCtrl" novalidate>
<div ng-form="innerForm" class="row" ng-repeat="wallet in wallets">
<div class="col item item-input-inset">
<label class="item-input-wrapper item-text-wrap">
<input name="wallet_{{wallet.id}}" type="number" ng-model="wallet.value" type="text" required/>
</label>
<span ng-show="innerForm['wallet_'+wallet.id].$error.required">!!!</span>
</div>
<div class="col item">{{ wallet.previous }}</div>
<button ng-click="sendValue(wallet)">
<i class="ion-android-send"></i>
</button>
<span class=ng-show="innerForm.$submitted==true && innerForm['wallet_'+wallet.id].$error.required">Required</span>
</div>
<button class="button" type="submit">Submit</button>
</form>
I have problem with ng-repeat when i search for a car its done but i delete the name i searched for the cars doesn't back to the view this is my html:
<ion-content lazy-scroll ng-class="{expanded:isExpanded}">
<div class="item-input-inset bar-light">
<label class="item-input-wrapper">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" ng-model="query" placeholder="Search">
</label>
</div class="content has-header">
<div>
<div class="list animate-fade-slide-in-right">
<a class="item item-thumbnail-left item-icon-right" ng-repeat='item in voitures[0] | filter: query' ng-model="data" ng-click="getID(item)" ui-sref="app.detailsVoiture({Id: item.idVoiture})">
<img image-lazy-src="img/{{item.photo}}.jpg" image-lazy-loader="android" image-lazy-distance-from-bottom-to-load="-200" image-lazy-distance-from-right-to-load="-200">
<h2 class="border-top" style="color:blue;">{{item.Modele.marque}} {{item.Modele.nom}}</h2>
<p >{{item.categorie}}</p>
<i class="icon ion-pricetag energized-900">{{item.prixLocation}}</i>
</a>
</div>
</div>
</ion-content>
How to access checked checkbox value in controller?
Here radio buttons array fill many radio buttons.
<label class="item item-input" ng-show="item.types !=''">
<div ng-repeat="type in item.types" style="margin-left:5px;">
<label class="item item-radio">
<input type="radio" name="group" ng-model="param.type">
<div class="item-content">
{{type.name}}
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
</div>
</label>
And Controller code
$scope.addItem = function(params) {
alert(params.type);
};
Given that you didn't post the rest of your controller code, I can't say for sure that this is the problem (or your only problem), but I suspect that changing ng-model to type and changing params.type to $scope.type in your addItem function would do the trick. Like so:
<label class="item item-input" ng-show="item.types !=''">
<div ng-repeat="type in item.types" style="margin-left:5px;">
<label class="item item-radio">
<input type="radio" name="group" ng-model="type">
<div class="item-content">
{{type.name}}
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
</div>
</label>
And in your controller:
$scope.addItem = function(params) {
alert($scope.type);
};