Collection repeat list inside Ionic Pop Up - angularjs

I have a collection repeat list with a search bar on top of the list (that is inside ionic pop up body). On the real device (Android 4.4), the list displays only 9 records.
I have a codepen created collection repeat inside ionic pop up. Here it displays all the records, but not on the actual device.
Recently I updated from Ionic 1.1.1 to Ionic 1.2.4 . Is it a problem because of the new Ionic version, I also tried Ionic 1.2.4's nightly build it also dint work.
Does the phone's browser version cause a difference, My phone's browser version is "Mozilla/5.0(Linux 4.4.2; en-us; 6043D Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) version/4.0 chrome/ 30.0.0 Mobile Safari/537.36."
Here is the HTML code of the ionic pop up.
<div class="list list-inset" ng-style="{ 'display': 'inline-flex', 'padding': '0'}">
<label class='item item-input' ng-style='{ 'border-right-color': '#FFFFFF'}'>
<i class='icon icon-left ion-ios7-search placeholder-icon''></i>
<input type='text' ng-model='search' placeholder='Search'>
</label>
<a class='button button-icon icon ion-ios7-close-empty placeholder-icon'
ng-style='{ 'color': '#B83E2C' }'
on-touch='clearSearch()''>
</a>
</div>
<div class='listPopUpHeight'>
<ion-scroll direction="y" class="available-scroller" style="height:350px">
<ion-list>
<ion-item
class="dataSourceItem"
collection-repeat="item in dataSource | filter:search"
collection-item-width="100%"
item-height="15%"
on-tap="tapped(item)">
{{item.Text}}
</ion-item>
</ion-list>
</ion-scroll>
</div>
Here is the JS code:
angular.module('ionicApp', ['ionic'])
.controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
$scope.dataSource = [];
$scope.showList = function(){
var list=[];
for (var i = 0; i < 1000; i++) {
list.push({ 'Id': i, 'Text': 'Text_' + i });
}
$scope.dataSource = list;
var listPopup = $ionicPopup.show({
templateUrl: 'popupTemplate.html',
title: 'List',
scope: $scope,
buttons: [
{ text: 'Cancel' },
]
});
};
});
Is there something I am missing out. Kindly do reply.
Thanks in advance :)

Please check below link. I made a popup with radio button with searchbar for Ionic v1.
https://codepen.io/engabdalb/pen/LYpWbZa
HTML
<a class="item" ng-click="open('aracyakit.html')">
Yakıt
<span style="color:#0097A4" style="color:#0097A4" class="item-note" >
{{arackayit.araba_yakit}}
</span>
</a>
<script id='aracyakit.html' type='text/ng-template'>
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="arama" placeholder="Arama">
</label>
<ion-radio name="araba_yakit" id="araba_yakit" ng-repeat="ay in arabayakitlari | filter:arama" class="wrapping-list" ng-model="arackayit.araba_yakit" ng-value="'{{ay.value}}'">{{ay.name}}</ion-radio>
</script>
<a class="item" ng-click="open('aracvites.html')">
Vites
<span style="color:#0097A4" style="color:#0097A4" class="item-note" >
{{arackayit.araba_vites}}
</span>
</a>
<script id='aracvites.html' type='text/ng-template'>
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="arama" placeholder="Arama">
</label>
<ion-radio name="araba_vites" id="araba_vites" ng-repeat="av in arabavitesleri | filter:arama" class="wrapping-list" ng-model="arackayit.araba_vites" ng-value="'{{av.value}}'">{{av.name}}</ion-radio>
</script>
CSS
.popup-body {
padding: 10px;
overflow: auto;
width: 100%;
}
.popup-open .popup-backdrop,
.popup-open .popup {
pointer-events: auto;
width: 100%;
}
.popup-head {
padding: 0px 0px;
border-bottom: 1px solid #eee;
text-align: center;
}
JS
$scope.arackayit = [];
$scope.arabavitesleri = [
{ value: "Otomatik", name: "Otomatik" },
{ value: "Manuel", name: "Manuel" }
]
$scope.arabayakitlari = [
{ value: "Dizel", name: "Dizel" },
{ value: "Benzin", name: "Benzin" },
{ value: "Benzin-LPG", name: "Benzin-LPG" }
]
$scope.open = function(clicked) {
$ionicPopup.confirm({
templateUrl: clicked,
scope: $scope,
buttons: [{
text: 'Iptal',
type: 'button-default',
onTap: function(e) {
// Change/ write here current page
$state.go('tab.aracekle');
}
}, {
text: 'Tamam',
type: 'button-positive',
onTap: function(e) {
//open next when OK clicked
switch (clicked) {
case 'aracyakit.html':
$scope.open('aracvites.html');
break;
//Do nothing when OK clicked
case 'aracvites.html':
default:
// code block
}
}
}]
});
}

Related

Save the click on a method

How can i save the titles selecteds of a ng-click in a method in controller?
<div ng-click="selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}">Item 1</span>
</div>
<div ng-click="selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}">Item 2</span>
</div>
<div ng-click="selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}">Item 3</span>
</div>
I am editing a qlik sense extension and need to save the selections in the app.
A better idea would be to identify objects with a unique identifier rather than a title that can be repeated. If the dimension object has an ID(or some other unique value) use it.
Adapt code below to your needs:
var app = angular.module("myModule", []);
app.controller("myCtrl", function($scope) {
var vm = this;
vm.dimensions = [
{
title: 'Title 1'
},{
title: 'Title 2'
},{
title: 'Title 3'
},{
title: 'Title 4'
},{
title: 'Title 5'
},{
title: 'Title 6'
},
];
vm.selected = [];
vm.selectItem = function(item, event) {
if(!vm.isSelected(item)) {
vm.addItem(item);
} else {
vm.removeItem(item);
}
// Show selected list
console.log(vm.selected);
}
vm.isSelected = function(item) {
return vm.selected.indexOf(item.title) != -1;
}
vm.addItem = function(item) {
vm.selected.push(item.title);
}
vm.removeItem = function(item) {
var index = vm.selected.indexOf(item.title);
vm.selected.splice(index, 1);
}
});
.element {
margin: 20px;
line-height: 10px;
border-bottom: 1px solid black;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myModule">
<div ng-controller="myCtrl as ctrl">
<div ng-repeat="dimension in ctrl.dimensions" ng-click="ctrl.selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}" class="element">
{{ dimension.title }}
<span ng-if="ctrl.isSelected(dimension)">- checked</span>
</span>
</div>
</div>
</div>

searchable drop down in AngularJs

I am fetching data from API and I need a searchable dropdown so that when I start typing it shows me the data coming from the API. Currently I have this piece of code.
<select class="formControl" name="repeatSelect" id="repeatSelect" ng-model="facilitiesData.business_id">
<option ng-repeat="option in businesses" value="{{option.id}}">{{option.business_name}}</option>
</select>
Thanks.
Probably you are looking for this. This could be one of the solution.
This has different type of typeaheads. You can pick one as per your needs.
<input type="text" ng-model="customPopupSelected" placeholder="Custom popup template" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
Note - You will require a library ui-bootstrap-tpls which is officially created by AngularJS team.
Try this. you cannot directly put textbox inside option and filter select based on it. but this is one way that you can don so. another way is to use plugin or angular material design.
// Angular
var myApp = angular.module('app', []);
myApp.controller('ListCtrl', function($scope) {
$scope.items = [{
'name': 'Item 1'
}, {
'name': 'Item 2'
}, {
'name': 'Account 3'
}, {
'name': 'Account 4'
}, {
'name': 'Item 5'
}, {
'name': 'Item 6'
}, {
'name': 'User 7'
}, {
'name': 'User 8'
}];
});
// jQuery
$('.dropdown-menu').find('.dontClose').click(function(e) {
e.stopPropagation();
});
.dropdown.dropdown-scroll .dropdown-menu {
max-height: 200px;
width: 60px;
overflow: auto;
}
.search-control {
padding: 5px 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<div class="dropdown dropdown-scroll" ng-app="app">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">Select <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1" ng-controller="ListCtrl">
<li role="presentation" class="dontClose">
<div class="input-group input-group-sm search-control">
<span class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</span>
<input type="text" class="form-control" placeholder="Query" ng-model="query"></input>
</div>
</li>
<li role="presentation" ng-repeat='item in items | filter:query'> {{item.name}}
</li>
</ul>
</div>
you can use datalist tag also If you want to build your own searchable dropdown ..Here is the working code:
HTML Part:
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
<form ng-submit="click(search);">
<label class="child-label" for="existing-phases">Existing: </label>
<input type="text" ng-model="search" list="names">
<datalist id="names" class="form-control" ng-model="name">
<option value=''>-- select an option --</option>
<option ng-repeat="option in contacts | filter:search | limitTo:3" value="{{option.name}}"></option>
</datalist>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
JS Part:
var app = angular.module('app', []);
app.controller('myCtrl', function($scope) {
$scope.showContacts = function() {
$scope.contacts = [{
id: 1,
name: "Ben",
age: 28
}, {
id: 2,
name: "Sally",
age: 24
}, {
id: 3,
name: "John",
age: 32
}, {
id: 4,
name: "Jane",
age: 40
}];
};
$scope.showContacts();
$scope.click = function(MyData) {
alert(JSON.stringify(MyData));
};
});
Working Demo is available here..https://plnkr.co/edit/hamW3F05YUPrWwS3RmmG?p=preview
You're in the right path. All you need to do now is create an http service or factory that triggers an API call every keypress, and the result of which populates your $scope.businesses array.
If you want to build searchable drop-down on your own then you can make use of filters.searchable drop-down with filters using textbox
If you want to go for a plugin check angular multi select
I've recenlty used in one of my projects. It is a flexible plugin and it allows multi-select also.
You can use dropdown select plugin
JS
const app = angular.module('DropdownSelectApp', ['DropDownSelect']);
HTML
<dropdown-select dd-model="exampleModel" dd-data="exampleItemList" dd-label="labelName" >
See this like for demo: https://saravanajd.github.io/Angularjs-Dropdown-Search/

Angular Google line chart directive

I want to make an angular attribute directive for Google line charts rather than manually load the chart in controllers because the first time when the page loads the chart draws easily and navigate to another page and controller and return back previous page so its not draw chart. Here I am drawing the chart like below but I want to make an angular directive because its not working with page navigation
<ion-view title="Select Medicines" catch-view="false">
<ion-content>
<div class="list med-select inven-l">
<div class="list" style="background-color:52487B;">
<div class="row item item-icon-left item-icon-right item-stable">
<div curve_chart style="width:100%; height: 250px" > </div>
</div>
<div class="row item item-icon-left item-icon-right item-stable" style="margin-bottom: 5px;" ng-click="gotoDetail(weekSales.OrderNo)" ng-repeat="weekSales in WeeklyData.orders | orderBy:'CreatedOn'">
<div class="col col-70">
<h2>{{weekSales.Customer.FName}} {{weekSales.Customer.LName}} </h2>
<p>Order No: MY-{{weekSales.OrderNo}} - {{weekSales.CreatedOn| date : 'dd'}}/{{weekSales.CreatedOn| date : 'MM'}}/{{weekSales.CreatedOn| date : 'yyyy'}}</p>
</div>
<div class="col col-20">
<span style="color:#d5d1e7">₹ {{weekSales.Amount}}</span>
</div>
<div class="col col-10">
<i class="icon ion-chevron-right"></i>
</div>
</div>
</div>
</div>
</ion-content>
angular.module('controllers.Chemist_sales_monthlyCtrl', [])
.controller('Chemist_sales_monthlyCtrl', function($scope, $state, $ionicHistory,serverRepo,$ionicLoading,profileInfo) {
$scope.data = {};
$scope.gotoDetail = function(orderNo){
//alert(orderNo)
profileInfo.orderId=orderNo
$state.go('pannel.chem_order_history_Detail');
}
$scope.myGoBack= function(){
$ionicHistory.goBack()
}
$scope.$on('$ionicView.enter', function() {
$ionicLoading.show({
template: '<ion-spinner icon="spiral"></ion-spinner>',
noBackdrop:false
});
serverRepo.salesMonthly().then(function(objS){
console.log(objS)
$scope.monthlyData=objS.data;
angular.forEach(objS.data.orders, function(value, key) {
objS.data.orders[key].CreatedOn=new Date(objS.data.orders[key].CreatedOn)
})
var options = {
legend: { position: 'bottom' },
curveType: 'function',
titlePosition: 'in',
axisTitlesPosition: 'in',
hAxis: {
textPosition: 'in',
minValue: 0,
textStyle:{color: "#fff"}
},
vAxis: {
minValue: 0,
maxValue: 13,
textPosition: 'in',
textStyle:{color: "#fff"},
minorGridlines:{color: "#ccc"}
},
lineWidth: 6,
fontSize:11,
chartArea:{left:0,top:0,width: '100%', height: '100%',backgroundColor: '#43396D'},
colors: ['#32BD76'],
animation:{
duration: 1500,
easing: 'out',
startup: true
}
};
google.charts.setOnLoadCallback( function () {
// Create and populate the data table.
console.log(objS.data.labels)
console.log(objS.data.datasets.data)
var data = new google.visualization.DataTable();
data.addColumn('string', 'labels');
data.addColumn('number', 'data');
for(i = 0; i < objS.data.labels.length; i++)
data.addRow([objS.data.labels[i], objS.data.datasets.data[i]]);
// Create and draw the visualization.
var chart = new google.visualization.LineChart(document.getElementById('curve_chartmonthly')).
chart.draw(data, options);
});
$ionicLoading.hide();
},function(objE){
// alert(JSON.stringify(objE));
console.log("Error:-\n"+JSON.stringify(objE));
$ionicLoading.hide();
});
});
})

Push Item to Model within a nested Repeat doesn't appear in view

I've done a small working snippet so far to handle 'notes'. But now I do need to add Items at Runtime to my Model.
That's the JSON behind my Model:
[
{
"DocId":"SomeGuid",
"Items":[
{
"Content":"SomeContent",
"Date":"SomeDate",
"OrderBy":0,
"Page":1,
"Title":"SomeTitle"
},
{
"Content":"SomeContent",
"Date":"SomeDate",
"OrderBy":0,
"Page":2,
"Title":"SomeTitle"
}
]
},
{
"DocId":"SomeGuid",
"Items":[
{
"Content":"SomeContent",
"Date":"SomeDate",
"OrderBy":0,
"Page":1,
"Title":"SomeTitle"
},
{
"Content":"SomeContent",
"Date":"SomeDate",
"OrderBy":0,
"Page":2,
"Title":"SomeTitle"
}
]
}
]
I now need to add a new Entry in one of those .Items.
That's my code:
$scope.AddNode = function (docID, page) {
var item;
$scope.data.forEach(function(object) {
if (object.DocId == docID) {
var newNode = { Content: "", Page: page, Title: "Neue Haftnotiz", Date: "16.19.05",Id: 0,Order:0,DocId:docID };
$scope.data[$scope.data.indexOf(object)].Items.push(newNode);
return;
}
});
(btw is there any $scope.data.FindByAttribute('docId',docID)? - I couldn't find anything in this regard)
It'll push the new Item in my array, but won't update my view.
You see the results here: (Black = old, Red = pushed)
My View just doesn't care if there is a new element or not - here's the template:
template: '<div class="root" >\
<div class="group" id="{{groupId}}-{{$index}}" ng-repeat-start="doc in ngModel" sv-root sv-part="doc.Items">\
<div class="groupHeader" ><h4 style="margin-bottom:0px;" >{{doc.DocId}}</h4></div>\
<div class="note panel" ng-repeat="item in doc.Items" sv-element>\
<div class="header">\
<h5>\
<a ng-click="toggleCollapsedStates($parent.$index,$index)" class="anchor" href="#{{groupBaseId}}-{{$parent.$index}}-{{$index}}">{{item.Title}} - Seite: {{item.Page}}</a>\
</h5>\
<div class="button collapsed" id="{{groupBaseId}}-{{$parent.$index}}-{{$index}}-expander" ></div>\
<div id="{{groupBaseId}}-{{$parent.$index}}-{{$index}}-menu" class="collapse">\
<input type="button" class="button delete" ng-click="deleteNode($parent.$index,$index)"/>\
<input type="button" class="button edit" ng-click="editNode($parent.$index,$index)" id="{{groupBaseId}}-{{$parent.$index}}-{{$index}}-edit"/>\
<input type="button" class="button reference" ng-click="openReference($parent.$index,$index)"/>\
</div>\
</div>\
<div id="{{groupBaseId}}-{{$parent.$index}}-{{$index}}" data-parent="#{{groupId}}-{{$parent.$index}}" class="collapse">\
<textarea class="area" maxlength="255" id="{{groupBaseId}}-{{$parent.$index}}-{{$index}}-textarea" readonly>{{item.Content}}</textarea>\
</div>\
</div>\
</div>\
<div ng-repeat-end></div>\
</div>',
$scope.$apply() does the job
And the answer is too short.

How to display the content from controller on HTML page in angularjs?

I am new to angularjs. I am trying to display the content from controller to the HTML but I am getting the data in console and I am not able to show it on the browser.
My html code:
<ion-list >
<ion-item ng-repeat="item in taskdetails" item="item" class="item-remove-animate item " class="itembg" on-swipe-right="showcard(item._id)" on-hold=" data.showReorder = !data.showReorder">
<span class="toptask" ng-hide="task.hide">
<span style="opacity:0.8"> {{ item.title| limitTo:10 }}<span ng-show="item.title.length> 10"><b> ...</b></span></span>
<small class="time " style="float:right;"> <i class="button button-icon icon ion-play balanced" ng-class="{ 'ion-pause assertive': !data.paused, 'ion-play balanced': data.paused}" ng-click="play5(item.id)" ></i>
</small>
<div style="float:right;margin-right:5px; font-size: 32px;
position: absolute;
right: 10px;
top: 10px;
color: black;" class="time icon ">
<i ng-class="{ 'ion-gear-b': data.paused, 'ion-loading-c spin': !data.paused}" class=" icon balanced" ng-click="showcard(item.id)"></i>
</div>
</span>
</ion-item>
</ion-list>
Controller
$scope.openTasks = function (impFlag, urgFlag) {
console.log("important came as: " + impFlag + " , urgent falg came as: " + urgFlag);
quadrantservice.gettask.get({
important: impFlag,
urgent: urgFlag
}).$promise.then(function (result) {
$scope.taskdetails = result;
console.log('task detailssssssssssssss' + JSON.stringify($scope.taskdetails));
/*$state.go('listoftask', {
important: impFlag,
urgent: urgFlag
});*/
});
$state.go('/listostasks');
}
I am getting the data in console but I am not able to display it on 'listoftasks' state.
You need $watch on your data change because intially data is not available so you need to watch the changes and reflect it accordingly.
$scope.$watch('taskdetails',function(newVal){
if(typeof newVal !='undefined'){
$scope.taskdetails=newVal;
}
});
//Place this in your maincontroller.

Resources