I am using ng-click and ng-show for pagination - angularjs

I am using ng-click and ng-show for pagination. In this case it keeps on creating new pages in both direction when ever buttons are clicked i.e it keeps on creating blank pages. It should stop at first and last page respectively. Here I have created three sub-pages for pagination the buttons should play only for this three sub pages.
Looking forward for any help.
thank you.
<div class="container" ng-app="tabApp">
<div class="row" ng-controller="TabController">
<div class="col-md-2">
<ul class="nav nav-pills nav-stacked">
<li>
<a href ng-click="setTab(tab+1)" class="btn btn-primary btn-lg" role="button">Next</a>
</li>
<li>
<a href ng-click="setTab(tab-1)" class="btn btn-primary btn-lg" role="button">Back</a>
</li>
</ul>
</div>
<div class="col-md-8">
<div class="jumbotron">
<div ng-show="isSet(1)">
<h1>Home page</h1>
<p>Welcome to the website!</p>
<p><a class="btn btn-primary btn-lg" role="button">Learn more</a></p>
</div>
<div ng-show="isSet(2)">
<h1>Profile page</h1>
<p>Profile information</p>
</div>
<div ng-show="isSet(3)">
<h1>Messages</h1>
<p> Some messages </p>
</div>
</div>
</div>
</div>
</div>
<script>
angular.module('tabApp', [])
.controller('TabController', ['$scope', function($scope) {
$scope.tab = 1;
$scope.setTab = function(newTab) {
$scope.tab = newTab;
};
$scope.isSet = function(tabNum) {
return $scope.tab === tabNum;
};
}]);
</script>
I have created a codepen

Related

how can fix data not showing with angularjs and laravel

Is anyone help me, when I start to code to show data in blade with angularJS, data not showing in the page, even the data exists in the console. This following code in my app.js
// app.js
$scope.view_tab = 'shop1';
$scope.changeTab = function(tab) {
$scope.view_tab = tab;
}
// List product
$scope.loadProduct = function () {
$http.get('/getproduct').then(function success(e) {
console.log(e.data);
$scope.products = e.data.product;
$scope.totalProduct = $scope.products.length;
$scope.currentPage = 1;
$scope.pageSize = 9;
$scope.sortKey = 'id_kain';
};
//index.blade.php
<div class="shop-top-bar">
<div class="shop-tab nav">
<a ng-class="{'active': view_tab == 'shop1'}" ng-click="changeTab('shop1')" data-toggle="tab">
<i class="fa fa-table"></i>
</a>
<a ng-class="{'active': view_tab == 'shop2'}" ng-click="changeTab('shop2')" data-toggle="tab">
<i class="fa fa-list-ul"></i>
</a>
</div>
</div>
<div class="shop-bottom-area mt-35">
<div class="tab-content jump">
<div class="tab-pane" ng-class="{active: view_tab == 'shop1'}">
<div class="row">
<div ng-repeat="data in filtered = ( products | filter:search ) | orderBy:sortData | itemsPerPage: 9" class="col-xl-4 col-md-6 col-lg-6 col-sm-6">
<div class="product-wrap mb-25 scroll-zoom">
<div class="product-img">
<a ng-click="showForm(data)">
<img class="default-img" ng-src="#{{ data.gambar_kain[0].gambar_kain }}" alt="">
<img class="hover-img" ng-src="#{{ data.gambar_kain[1].gambar_kain }}" alt="">
</a>
</div>
<div class="product-content text-center">
<h3>#{{data.nama_kain}}</h3>
<div class="product-price">
<span>#{{numberingFormat(data.data_kain[0].harga_kain)}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" ng-class="{active: view_tab == 'shop2'}">
<div dir-paginate="datas in filtered = ( products | filter:search ) | orderBy:sortData | itemsPerPage:9" class="shop-list-wrap mb-30">
<div class="row">
<div class="col-xl-4 col-lg-5 col-md-5 col-sm-6">
<div class="product-wrap">
<div class="product-img">
<a ng-click="showForm(datas)">
<img class="default-img" ng-src="#{{ datas.gambar_kain[0].gambar_kain }}" alt="">
<img class="hover-img" ng-src="#{{ datas.gambar_kain[1].gambar_kain }}" alt="">
</a>
</div>
</div>
</div>
<div class="col-xl-8 col-lg-7 col-md-7 col-sm-6">
<div class="shop-list-content">
<h3>#{{data.nama_kain}}</h3>
<div class="product-list-price">
<span>#{{numberingFormat(datas.data_kain[0].harga_kain)}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="pro-pagination-style text-center mt-30">
<dir-pagination-controls
max-size="1"
direction-links="true"
boundary-links="true" >
</dir-pagination-controls>
</div>
</div>
Data still not shows in the page, there are not errors in this page, but I don't know how can I fix this.
As I know there is two way to show data in Angular JS when you define the scopes then you need the ng-bind or ng-model to show data in the front end.
1- AngularJS Data Binding
live Example https://www.w3schools.com/code/tryit.asp?filename=G2DQQ2GSJ3EO
<div ng-app="myApp" ng-controller="myCtrl">
<p ng-bind="firstname "></p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstname = "John will be change";
});
</script>
2-AngularJS ng-model Directive
Live Example https://www.w3schools.com/code/tryit.asp?filename=G2DQQEUEPSOC
<div ng-app="myApp" ng-controller="myCtrl">
Name: <input ng-model="name">
<h1>You entered: {{name}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "John Doe";
});
</script>
NOTE: try with static data and then check that you have valid data to make it dynamic
I hope this helps you!

On clicking Search Button, display result in the next page

I searched for the solution but could not find the exact solution so posted here.
I have a search bar in the header menu. When search content is typed and clicked on search button, the result needs to be display in a new page (eg. result.html). API is used to fetch the searched result.
I have added js pseudo code below which will explain what I intend to do.
Thank you for the suggestion.
navigation
<nav class="navbar navbar-default navbar-fixed-top navbar-search-box animate" role="navigation">
<div class="row">
<div class="collapse navbar-collapse" >
<ul class="nav navbar-nav" id="main-nav">
<li> ... </li>
<li>
<div class="search-bar-search animate">
<div class="container" ng-controller="searchCtrl">
<div class="input-group">
<input type="text" class="form-control" id="q" ng-model="q" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button" ng-click="search()">Search</button>
</span>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</nav>
Search.js
var app = angular.module('myApp', ['ngRoute']);
app.service('searchService', function($http) {
this.getResult = function(q) {
// o/p is in JSON format
return $http.get('http://mydomainname/api/search/'+q);
}
});
app.controller('searchCtrl', function ($scope, searchService){
$scope.search = function (){
var q = $scope.q;
searchService.getResult(q).then(function (response){
$scope.result = response.data;
// redirect to new template (result.html) and display result
...
...
});
};
});

Call function on close of ngDialog

I open an alert dialog with ok button. On click calls a function. I need to call the same function when I close the alert dialog
<script type="text/ng-template" id="alertErrorTemplate.html">
<div class="form-wrp">
<div class="form-item">
<h2 class="box-title error-text" ng-class="{'box-left': leftAlign}"><span data-ng-bind="Web_Error" ng-show="showTitleText">Error: </span>{{alertText}}</h2>
<h2 class="box-text error-text" ng-class="{'box-left': leftAlign}" ng-show="secondaryText !== null">{{secondaryText}}</h2>
<div ng-show="alertItemList && alertItemList.length > 0" class="dialog-error-list error-text">
<ul>
<li ng-repeat="item in alertItemList">
{{ item }}
</li>
</ul>
</div>
</div>
<div class="form-item text-center">
<button ng-click="closeNgDialog()" class="btn btn-success btn-big" data-ng-bind="Web_OK">OK</button>
</div>
</div>
</script>
You can listen to 'ngDialog.closing' event like this :
$scope.$on('ngDialog.closing', function () {
//do what ever you want.
});

Passing Object from a table row to bootstrap modal

I'm trying to put to a modal the attributes of a clicked table row. I am using angularjs. Nothing happens in my code:
Basically this is my html code like below:
<tr ng-repeat="pokemons in pokemon">
<td>{{pokemons.pokemon_number}}</td>
<td>{{pokemons.pokemon_name}}</td>
<td>{{pokemons.type1}}</td>
<td>{{pokemons.type2}}</td>
</tr>
Then this is in my script tag:
var myApp = angular.module('myApp', [])
myApp.controller('SimpleController', ['$scope', '$http', function($scope, $http) {
$scope.findPokemon = function(filterKey){
$http.get('pokemon/search-by-name/' + filterKey).then(function(response) {
$scope.pokemon = response.data
})
}
$scope.getDetails = function(pokemons){
$scope.pokemonDetails = pokemons
$('#viewModal').modal('show');
}
}]) `
Modal:
<div id="pokemon-zoom" class="modal">
<div class="modal-content animate">
<div class="imgcontainer">
<span onclick="document.getElementById('pokemon-zoom').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="modal-container">
<img id="pokemon-image" src="Bulbasaur.jpg" height="200px" width="200px">
<div class="pokemon-details">
<h1>Pokemon Data</h1>
<div id="pokemon-data-text">
<p>Pokemon no: {{pokemonDetails.pokemon_number}}</p>
<p>Type1: {{pokemonDetails.type1}}</p>
<p>Type2: {{pokemonDetails.type12}}</p>
<p></p>
</div>
</div>
<div class="options">
<button class="options-link" href="#">Edit</a>
<button class="options-link" href="#">Delete</a>
</div>
</div>
</div>
</div>
Btw some parts there seem unnecessary i just included them
Here is the answer for your problem
HTML
<table>
<tr ng-repeat="pokemons in pokemon">
<td>{{pokemons.pokemon_number}}</td>
<td>
<button type="button" class="btn btn-default"
style="width:100px; height:25px"
ng-click="openModal(pokemons)"
data-toggle="modal" data-target="#pokemon-zoom" >
{{pokemons.pokemon_name}}</button>
</td>
<td>{{pokemons.type1}}</td>
<td>{{pokemons.type2}}</td>
</tr>
</table>
Modal Code is this
<div id="pokemon-zoom" class="modal">
<div class="modal-content animate">
<div class="imgcontainer">
<span onclick="document.getElementById('pokemon-zoom').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="modal-container">
<img id="pokemon-image" src="Bulbasaur.jpg" height="200px" width="200px">
<div class="pokemon-details">
<h1>Pokemon Data of</h1>
<div id="pokemon-data-text">
<p>Pokemon no: {{selected_pokemon.pokemon_number}}</p>
<p>Type1: {{selected_pokemon.type1}}</p>
<p>Type2: {{selected_pokemon.type12}}</p>
<p></p>
</div>
</div>
<div class="options">
<button class="options-link" href="#">Edit</button>
<button class="options-link" href="#">Delete</button>
</div>
</div>
</div>
</div>
your controller will be having a method with name openModal
$scope.openModal=function (ob){
$scope.selected_pokemon=ob;
}
Here is a LIVE DEMO
You're trying to show the modal by calling $('#viewModal').modal('show');, but your modal has id pokemon-zoom. Show the modal by calling $('#pokemon-zoom').modal('show');
Make sure the modal is defined within the scope of the Controller SimpleController so that it can access pokemonDetails!

Angularjs : How to display data after update on my UI

I have angular project My Requirement is : How to display data after update on my UI without refreshing, Data store in server i want it to display on Contact and Recent Tab immediately after Updating.
UI Bindings:
<li class="media contact-card">
<div class="media-left">
<a ui-sref=".viewClient({'clientId':client._id})">
<img class="media-object img-circle" src="https://placehold.it/42x42" alt="https://placehold.it/64x64">
<!--<div class="circle" ng-class="getRandomColorClass('Xipesh Gandhi')"><p>{{generateInitialChar('Dipesh Gandhi')}}</p></div>-->
</a>
</div>
<div class="media-body">
<div class="pull-left">
<h4 class="media-heading pull-left">{{client.firstName}} {{client.lastName}}</h4>
</div>
<div class="pull-right">
<a class="" ui-sref=".editClient({'clientId':client._id})"> <i class="glyphicon glyphicon-pencil" ></i></a>
<a class=""> <i class="glyphicon glyphicon-trash" ></i></a>
</div>
<div class="clearfix"></div>
<span>{{client.address}}</span>
<span>{{client.birthDate | date:'mediumDate'}}</span>
</div>
</li>
View :
<div class="tab-wrapper">
<tabset justified="true">
<tab heading="CONTACTS">
<div class="tab-content">
<div>
<div class="pull-right">
<a class="add-client-link" ui-sref=".client"> <i class="glyphicon glyphicon-plus" ></i> Add Contact </a>
</div>
<div class="clearfix"></div>
</div>
<div class="hr"></div>
<div class="scrollable-container">
<ul class="media-list">
<contact-card data-client="client" ng-repeat="client in clientList"></contact-card>
</ul>
</div>
</div>
</tab>
<tab heading="RECENT">
<div class="tab-content">
<div>
<div class="pull-right">
<a class="add-client-link" ui-sref=".client"> <i class="glyphicon glyphicon-plus" ></i> Create Meeting </a>
</div>
<div class="clearfix"></div>
</div>
<div class="hr"></div>
<div class="scrollable-container">
<ul class="media-list">
<contact-card data-client="client" ng-repeat="client in clientList"></contact-card>
</ul>
</div>
</div>
</tab>
</tabset>
</div>
Controller:
$scope.updateClientList = function(client, operation){
if(operations.ADD === operation){
//$scope.clientList.push({firstname: $scope.client.firstName, lastname: $scope.client.lastName});
//$scope.clientList.push(client);
$scope.clientList.push (client);
// $scope.clientList = [];
} else if(operations.EDIT === operation){
} else if(operations.DELETE === operation){
}
$state.go('meeting-home.viewClient', {'clientId':client._id});
};
Does anyone know how to do it?
Please comment $scope.clientList = []; in your code. it will work. Any how you are not mentioning UI binding details.

Resources