I am using Ionic & angular.js to create a cross platform application and I am not being able to fetch all the post from word-press using json offset parameter, it fetched only 10 post by default I am suing infinite scroll of Ionic and Angular.js functions to do so but not being able to fetch all the posts
#controller.js
angular.module('starter')
.controller('MenuCtrl', function MenuCtrl($http, $scope, $sce, $ionicScrollDelegate){
$scope.categories = [];
$http.get("http://bijay.sahikura.com/api/get_category_index/")
.then(function(returnedData){
$scope.categories = returnedData.data.categories;
$scope.categories.forEach(
function(element, index, array){
element.title = $sce.trustAsHtml(element.title);
});
console.log(returnedData);
},
function(err){
console.log(err);
});
$scope.doRefresh = function(){
$scope.recent_posts = [];
$http.get("http://bijay.sahikura.com/api/get_posts/")
.then(function(data){
console.log(data);
$scope.recent_posts = data.data.posts;
$scope.recent_posts.forEach(
function(element, index, array){
element.excerpt = element.excerpt.substr(0,100);
element.excerpt = element.excerpt + " ... पुरा पढ्नुहाेस";
element.excerpt = $sce.trustAsHtml(element.excerpt);
$scope.$broadcast('scroll.refreshComplete');
});
});
};
$scope.recent_posts = [];
$http.get("http://bijay.sahikura.com/api/get_posts/")
.then(function(data){
console.log(data);
$scope.recent_posts = data.data.posts;
$scope.recent_posts.forEach(
function(element, index, array){
element.excerpt = element.excerpt.substr(0,100);
element.excerpt = element.excerpt + " ... पुरा पढ्नुहाेस";
element.excerpt = $sce.trustAsHtml(element.excerpt);
});
});
**$scope.canLoadMore = function()
{
return true;
};
$scope.count=0;
$scope.loadMore = function(){
console.log($scope.count++);
$http.get("http://bijay.sahikura.com/api/get_posts/?offset= "+$scope.offset)
.then(function(data){
var newPosts = data.data.posts;
$scope.count_total = data.data.count_total;
newPosts.forEach(
function(element, index, array){
element.excerpt = element.excerpt.substr(0,100);
element.excerpt = element.excerpt + " ... पुरा पढ्नुहाेस";
element.excerpt = $sce.trustAsHtml(element.excerpt);
})
$scope.recent_posts.push.apply($scope.recent_posts, newPosts);
$scope.$broadcast('scroll.infiniteScrollComplete');
$scope.offset = +10 ;
})
};**
$scope.searchTextChanged = function(){
$ionicScrollDelegate.$getByHandle('mainScroll').scrollTop(true);
};
})
.controller('PostCtrl', function() {
//alert("hello!");
})
menucontent.html
<ion-view>
<ion-nav-bar class="bar-assertive">
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-heart">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-header-bar class="bar bar-assertive">
<div class="title"> <center>Hello</center> </div>
</ion-header-bar>
<div class="bar bar-subheader item-input-inset">
<label class="item-input-inset">
<i class="icon ion-ios-search placeholder-icon"> </i>
<input type="search" placeholder="Search..." ng-model="searchText" ng-change="searchTextChanged()"/>
</label>
</div>
<ion-content class="has-subheader" delegate-handle="mainScroll">
<ion-refresher
pulling-text="Update ..."
on-refresh="doRefresh()">
</ion-refresher>
<ion-list can-swipe="true">
<ion-item class="item item-thumbnail-left item-text-wrap item-icon-right" ng-repeat="post in recent_posts | filter: {title: searchText}">
<img 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>
<ion-infinite-scroll ng-if="canLoadMore()" on-infinite="loadMore()">
</ion-infinite-scroll>
</ion-content>
</ion-view>
Related
How can I get information from a select with angularjs and ionic1?
I'm trying to get the information from a JSON and put in the "select", until that part I got to do. But when I select the information from this "select" and try to get the id and the name that is in the "select", it is not showing.
My html -> igreja.html
<ion-view view-title="Igrejas">
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
<ion-content>
<form ng-submit="realizarLogin()">
<div class="list list-inset">
<ion-item class="item-input item-select--full">
<div class="input-label">
Selecione a sua igreja
</div>
<select ng-model="login" ng-options="y.Nome for (x,y) in igrejaEscolhida">
</select>
<h1> test: {{login.Nome}}</h1>
<h1> id: {{login.Id}} </h1>
</ion-item>
<button class="button button-block button-positive" type="submit">Entrar</button>
</div>
</form>
</ion-content>
</ion-view>
My routes.js
.state('app.igrejas', {
url: '/igrejas',
views: {
'menuContent': {
templateUrl: 'templates/igrejas.html',
controller: 'igrejasController'
}
}
})
My controller.js
.controller('igrejasController', function($scope, $ionicModal, $timeout, $stateParams, $ionicPopup, $state, $rootScope, $http, $sce) {
$http.get(linkIgrejas).then(function(data){
$scope.igrejaEscolhida = data.data;
console.log($scope.igrejaEscolhida);
$scope.igrejaEscolhida.forEach(function(element, index, array){
element.Id = element.Id;
element.Nome = element.Nome;
console.log(element.Id);
console.log(element.Nome);
})
})
$rootScope.login = {};
$scope.realizarLogin = function() {
var dadosDoLogin = {
params : {
nome: $rootScope.login.nome
}
}
$scope.selectUpdated = function(optionSelected) {
console.log('Updated');
console.log(optionSelected);
};
console.log($scope.selectUpdated);
$scope.loginF.Nome;
$scope.loginF.Id;
console.log($scope.loginF.Nome);
console.log($scope.loginF.Id);
$rootScope.teste = $rootScope.login.nome;
$scope.nomeIgreja = $rootScope.login.nome;
$scope.idIgreja = $rootScope.login.Id;
$rootScope.login.Id;
console.log($scope.nomeIgreja);
console.log($scope.idIgreja);
};
})
Could someone help me or show me what I'm doing wrong in the "select"?
Try to put the value itself to represent The id
<option ng-repeat="igrejaEscolhidas in igrejaEscolhida" value="{{ igrejaEscolhidas.Id }}">
{{ igrejaEscolhidas.Nome }}
</option>
then the ng-model with the select will take the Id from the value of the selected option.
I changed my Igrejas.html and controller.js
Igrejas.html
<ion-view view-title="Igrejas">
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
<ion-content>
<form ng-submit="realizarLogin()">
<div class="list list-inset">
<ion-item class="item-input item-select--full">
<div class="input-label">
Selecione a sua igreja
</div>
<select ng-model="login.nome">
<option ng-repeat="igrejaEscolhidas in igrejaEscolhida">
{{ igrejaEscolhidas.Nome }}
{{ igrejaEscolhidas.Id }}
</option>
</select>
</ion-item>
<button class="button button-block button-positive" type="submit">Entrar</button>
</div>
</form>
</ion-content>
</ion-view>
My controller.js
.controller('igrejasController', function($scope, $ionicModal, $timeout, $stateParams, $ionicPopup, $state, $rootScope, $http, $sce) {
$http.get(linkIgrejas).then(function(data){
$scope.igrejaEscolhida = data.data;
console.log($scope.igrejaEscolhida);
$scope.igrejaEscolhida.forEach(function(element, index, array){
element.Id = element.Id;
element.Nome = element.Nome;
console.log(element.Id);
console.log(element.Nome);
})
})
$rootScope.login = {};
$scope.realizarLogin = function() {
$rootScope.teste = $rootScope.login.nome;
console.log($rootScope.teste);
};
})
When I tested this way I managed to get the id and name, but they are together like this in this print, I need to get them separated, how do they separate them in angularjs?
My print :
http://prntscr.com/fhg4py
Or someone knows how I can get the id and separate name, being that I have this id and that name will come from the same select? I got them together.
I have a list of data that populates an ionic list with delete function when we swipe the list to left.
I am able to make the delete function to work, however after the success response and the list get refreshed, the delete button still shown in the index that we clicked before.
I am using $scope.data.splice($index, 1);
this is my code
HTML
<ion-pane>
<ion-view view-title="Incoming list">
<ion-nav-buttons side="right">
<a class="button" href="#/app/fg-in-add">
<i class="icon ion-plus"></i>
</a>
<a class="button" href="#/app/scanner-fg-in">
<i class="icon ion-qr-scanner"></i>
</a>
</ion-nav-buttons>
<ion-content class="has-header">
<div class="list">
<div class="item item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="fgin.search" class="textUppercase">
</label>
<button class="button button-small">
<i class="icon ion-search"></i> Search
</button>
</div>
</div>
<ion-list show-delete="false" can-swipe="true">
<ion-item ng-repeat="x in data track by $index" class="item-remove-animate">
<!-- <ion-option-button class="button-positive icon ion-edit" on-touch="deleteFGin({{x.mif_no}})"></ion-option-button> -->
<ion-option-button class="button-assertive icon ion-trash-a" on-touch="Delete(x.mif_no,x.item_no,$index); x.deleted = true;"></ion-option-button>
<h3><i class="icon ion-android-apps"></i> {{x.mif_no}} <i class="icon ion-ios-arrow-thin-right"></i> {{x.item_no}}</h3>
<hr />
<div class="descr"><i class="icon ion-grid"></i> <span class="judul">{{x.part_no}}</span> <i class="icon ion-ios-arrow-thin-right"></i> {{x.part_name}}</div>
<div class="descr indentlitte">{{x.qty}} {{x.u_measure}}<i class="icon ion-ios-arrow-thin-right"></i> {{x.rack_no}}</div>
<span class="badge badge-clear">{{x.date}}</span>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
</ion-pane>
JS
$scope.Delete = function(docno,itemno,index){
$http({
method: "post",
url: apiServer + "/fg-in-del.php",
data: {
mifno: docno,
itemno: itemno,
Dbserver: window.localStorage.getItem("server"),
Dbuser: window.localStorage.getItem("username"),
Dbpass: window.localStorage.getItem("password"),
Dbname: window.localStorage.getItem("dbname"),
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
}).then(function(response) {
if (response.data == 1){
var alertPopup = $ionicPopup.alert({
title: 'Delete',
template: 'Data has been deleted.'
});
$scope.data.splice(index, 1);
}else {
var alertPopup = $ionicPopup.alert({
title: 'Delete',
template: 'Failed to delete data.'
});
console.log(response.data);
}
}, function(response) {
$scope.data=response.data;
var alertPopup = $ionicPopup.alert({
title: 'Delete',
template: 'Failed to delete data.'
});
});
}
This is so weird because I noticed the exact same thing with my app last night, I think it might be a bug.
I opted for refreshing the entire list from the server, but if that's not an option for you, you could inject the $ionicListDelegate in your controller and call $ionicListDelegate.closeOptionButtons() after splicing.
I have a view with one list item. After user clicked on this item, the modal form show. When user change value and close modal, the item-not not updating.
View:
<ion-view ng-controller="settingsController">
<ion-content>
<div class="list">
<ion-item class="item-icon-left" ng-click="openLanguageModal()">
<i class="icon ion-chatboxes"></i>
{{'Language'| translate}}
<span class="item-note">
<div ng-bind="choice"></div>
</span>
</ion-item>
</div>
</ion-content>
<script id="language-modal.html" type="text/ng-template">
<div class="modal">
<ion-header-bar>
<!-- <button class="button button-full button-dark" ng-click="closeLanguageModal()">{{'Done' | translate}}</button> -->
<button class="button button-clear button-positive pull-right" ng-click="closeLanguageModal()">
{{'Done' | translate}}
</button>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-radio ng-model="choice" ng-value="'en'"> English </ion-radio>
<ion-radio ng-model="choice" ng-value="'ru'"> Русский </ion-radio>
</ion-list>
</ion-content>
</div>
</script>
</ion-view>
Controller:
app.controller('settingsController', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('language-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.languageModal = modal;
})
$scope.choice = "en";
$scope.openLanguageModal = function() {
$scope.languageModal.show();
}
$scope.closeLanguageModal = function() {
$scope.languageModal.hide();
};
$scope.$on('$destroy', function() {
$scope.languageModal.remove();
});
});
I dont understand why the ng-bind didnt updates, help please
Try to use:
$scope.model.choice = "en";
in a main Controller (so that all other view controllers could inheritate this info).
and in all view (settings and language-modal) modify to:
ng-model="model.choice"
due to prototypal inheritance...
Here it is a working demo: http://codepen.io/beaver71/pen/XXaROB
I'm creating an app and I added ion-footer-bar, the problem is that ion-footer-bar stay on top the ion-list on last record. Looking for any solution I found to use $scope.$broadcast('scroll.resize'); but it not solved my problem.
How could I solve this ?
Controller
var app = angular.module('starter');
app.controller('EmpresaCtrl', function($scope, $state, $ionicLoading, EmpresaAPIService, AppConstants, APP_MESSAGES){
$scope.moreData = false;
var offset = 0;
$scope.items = [];
$scope.loadMore = function(){
EmpresaAPIService.getAllEmpresas(offset)
.success(function(data){
if(data.result.length === 0){
$scope.moreData = true;
}else{
angular.forEach(data.result, function(empresa){
var image = empresa.Empresa.imagem;
empresa.Empresa.imagem = AppConstants.webServiceUrl + "/app/webroot/img/empresas/" + image;
$scope.items.push(empresa);
})
offset += 10;
}
$scope.$broadcast('scroll.infiniteScrollComplete');
$scope.$broadcast('scroll.resize');
})
.error(function(err){
$ionicLoading.show({ template: APP_MESSAGES.internetOut, noBackdrop: true, duration: 2000 });
});
};
$scope.getEmpresa = function(id){
var params = {id:id};
$state.go('tab.detalheEmp', params);
}
});
index.html
<body ng-app="starter" animation="slide-left-right-ios7">
<ion-nav-bar class="bar bar-header bar-assertive" align-title="center">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
<ion-footer-bar class="bar-dark" ng-controller="AnuncioCtrl">
<div ng-model="loading" ng-show="loading">
<img src="img/loading.gif" width="30" height="30">
</div>
<img ng-src="{{banner}}" style="max-width:100%;display:block;margin:0 auto">
</ion-footer-bar>
</body>
empresa.html
<ion-view view-title="Empresas">
<ion-content class="padding" has-footer="true" scroll="true">
<div class="item item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-ios-search placeholder-icon"></i>
<input type="text" ng-model="pesquisar" placeholder="Pesquisa rápida...">
</label>
</div>
<ion-list>
<ion-item class="item item-thumbnail-left"
ng-repeat="item in items | filter:pesquisar"
type="item-text-wrap"
ng-click="getEmpresa({{item.Empresa.id}})" >
<img ng-src='{{item.Empresa.imagem}}'>
<div style="font-weight:bold;" class="item-text-wrap">{{item.Empresa.nome}}</div>
<div style="font-size:small" class="item-text-wrap">{{item.Empresa.tipo}}</div>
<div style="font-size:small">{{item.Empresa.endereco}}</div>
<div style="font-size:small">{{item.Empresa.telefone}}</div>
<a href="tel:{{item.Empresa.telefone}}" class="button button-small button-balanced icon ion-ios-telephone">
</a>
</ion-item>
<ion-infinite-scroll on-infinite="loadMore();" distance="1%" ng-if='!moreData'></ion-infinite-scroll>
</ion-list>
</ion-content>
</ion-view>
Solved the problem. It simple to solve. I add class on tag <ion-nav-view class="has-footer"> and works like charm.
I am just trying to follow this example.
Here is my code:
angular.module('starter.controllers', [])
.controller('PaymentListCtrl', function ($scope,$ionicModal,$timeout) {
$scope.firstName = "John";
$scope.productItems = [
{
name: 'Product 1',
price: '$50.00'
},
{
name: 'Product 2',
price: '$45.00'
}
];
$scope.message = 'Everyone come and see how good I look!';
$ionicModal.fromTemplateUrl('modal_transaction_code.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal
})
$scope.openModal = function() {
$scope.modal.show()
}
$scope.closeModal = function() {
$scope.modal.hide();
};
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
});
Modal Form
<label class="item item-radio" id="hashtagRadio" ng-controller="PaymentListCtrl">
<input type="radio" name="settings-group" value="search">
<div class="item-content">
<span class="ion-pound"></span> <span id="hashtagInput">MODAL FORM</span>
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
its simple..!
<body ng-app="starter" ng-controller="PaymentListCtrl">
<ion-pane>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-content>
<button
class="button button-full button-assertive"
style = "margin-top: 0px;"
ng-click = "openModal()">
Open modal
</button>
</ion-content>
</ion-pane>
</body>
</html>
<script id="modal_transaction_code.html" type="text/ng-template">
<ion-modal-view class="mdx-modal" >
<ion-header-bar class="dark">
<div class="title text-center">Hola</div>
<button class="button button-clear ion-close" ng-click="closeModal()"></button>
</ion-header-bar>
<ion-view>
<ion-content class=" content-stable" >
<label class="item item-radio" >
<input type="radio" name="settings-group" value="search">
<div class="item-content">
<span class="ion-pound"></span> <span >MODAL FORM</span>
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
</ion-content>
</ion-view>
</ion-modal-view>
</script>
make sure, above code remains in same .html file
and PaymentListCtrl controller code is right..!
hope u make it..!