How to implement Load More Button in angular 2 - angular2-routing

I want to add load more button in my project.I want to call an api on load more button and display the result.How i will implement this, in my case i am getting 200 result at a time because i have set limit 200 but i want a load more button in my code so that i can lazy load.i want to call api on button click.
Html
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="margin-20">
</div>
<form [formGroup]="transactionForm" (ngSubmit)="searchTransaction(transactionForm.value)" >
<div class="form-group col-xs-2">
<label>Workshop</label>
<select class="form-control" [(ngModel)]="selectedWorkShop" formControlName="workshops">
<option value="" selected>--select--</option>
<option *ngFor="let workshop of workshops" value= {{workshop.id}}>{{workshop.name}}</option>
</select>
<small *ngIf="!transactionForm.controls.workshops.valid" class="text-danger">Required</small>
</div>
<div class="form-group col-xs-2">
<label>Start Date</label>
<input class="form-control" placeholder="Choose Date" [ngModel]="startDate" formControlName="startDate" (focus)="toggleDatePicker1(true)"
readonly />
<date-picker *ngIf="showTimePicker1" [initDate]="startDate" (onDatePickerCancel)="toggleDatePicker1($event)" (onSelectDate)="setStartDate($event)"></date-picker>
<small *ngIf="!transactionForm.controls.startDate.valid" class="text-danger">Required</small>
</div>
<div class="form-group col-xs-2">
<label>End Date</label>
<input class="form-control" placeholder="Choose Date" [ngModel]="endDate" formControlName="endDate" (focus)="toggleDatePicker2(true)"
readonly />
<date-picker *ngIf="showTimePicker2" [initDate]="endDate" (onDatePickerCancel)="toggleDatePicker2($event)" (onSelectDate)="setEndDate($event)"></date-picker>
<small *ngIf="!transactionForm.controls.endDate.valid" class="text-danger">Required</small>
</div>
<!--<div class="form-group col-xs-2">
<label>From Date</label>
<input class="form-control" placeholder="Choose Date" [ngModel]="date" formControlName="date" (focus)="toggleDatePicker(true)"
readonly />
<date-picker *ngIf="showTimePicker" [initDate]="date" (onDatePickerCancel)="toggleDatePicker($event)" (onSelectDate)="setDate($event)"></date-picker>
</div>-->
<div class="margin-20 col-xs-12">
<button type="submit" class="btn btn-primary" [disabled]="!transactionForm.valid">Search</button>
<img *ngIf="loading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA=="
/>
</div>
</form>
</div>
</div>
</div>
<br><br>
<div class="container">
<div class="row">
<div class="col-xs-12">
<p *ngIf="isNoresult"><em>No Result Found</em></p>
<table class='table table-hover' *ngIf="transactions">
<thead>
<tr>
<th>User ID</th>
<th>Txn ID</th>
<th>Order Id</th>
<th>Mode</th>
<th>Transaction Type</th>
<th>Amount</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let transaction of transactions ">
<td>{{ transaction.user_id }}</td>
<td>{{ transaction.txn_id }}</td>
<td>{{ transaction.order_id }}</td>
<td>{{ transaction.mode }}</td>
<td>{{ transaction.transaction_type }}</td>
<td>{{ transaction.amount | number : '1.2-2' }}</td>
<td>{{ transaction.date * 1000 | date:'dd-MM-yyyy' }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Component
import { Component, OnInit } from '#angular/core';
import { FormGroup, AbstractControl, FormBuilder, Validators } from '#angular/forms';
import { Router } from '#angular/router';
import{DatePipe} from '#angular/common';
import { AlertService } from '../../../_services/index'
import { TransactionDetailsServices } from './transactionDetails.service';
// import { CustomerFilter, Customer } from '../models/index';
#Component({
selector: 'transactionDetails',
templateUrl: './transactionDetails.html'
})
export class TransactionDetails implements OnInit {
public transactionForm :FormGroup;
public workshops:any="";
public selectedWorkShop="";
public showTimePicker1:boolean;
public showTimePicker2:boolean;
public startDate=new Date();
public endDate=new Date();
public transactions:any;
public loading:boolean;
public isNoresult:boolean;
public offset:number=0;
constructor(
private fb:FormBuilder,
private alertService: AlertService,
private transactionDetailsService: TransactionDetailsServices,
private datePipe:DatePipe
) {
}
public phone: any;
ngOnInit() {
// const phoneRegex = `^[2-9]{2}[0-9]{8}$`;
// this.searchCustomerForm = this.fb.group({
// phone: ['', [Validators.required, Validators.pattern(phoneRegex)]],
// phoneCC: [{value:'',disabled:true}]
// });
// this.orderForm = this.fb.group({
// categories: this.listCategory()
// });
this.transactionForm=this.fb.group({
workshops:[this.listWorkshop(),Validators.required],
startDate:['',Validators.required],
endDate:['',Validators.required]
})
}
listWorkshop() {
this.weDoShoesCMSService.listWorkshop().subscribe(res => {
this.workshops = res;
this.selectedWorkShop="";
console.log(res);
},
err => {
this.alertService.error(err);
});
}
toggleDatePicker1(status: boolean): void {
this.showTimePicker1 = status;
}
toggleDatePicker2(status: boolean): void {
this.showTimePicker2 = status;
}
setStartDate(date: any): void {
this.startDate = date;
console.log(this.startDate);
}
setEndDate(date: any): void {
this.endDate = date;
console.log(this.endDate);
}
searchTransaction(model:any){
this.loading=true;
console.log(model);
model.startDate=this.filterDate(model.startDate);
model.endDate=this.filterDate(model.endDate);
console.log(model.startDate);
console.log(model.endDate);
this.transactionDetailsService.searchTransaction(model).subscribe(res=>{
this.transactions=res;
if(res==null){
this.isNoresult=true;
this.loading=false;
}
else{
this.isNoresult=false;
console.log(res);
this.loading=false;
}
},
error=>{
this.alertService.error(error);
this.loading=false;
});
}
filterDate(date){
return Date.parse(this.datePipe.transform(date, 'yyyy-MM-dd'))/1000;
}
convertDate(date){
return Date.parse(this.datePipe.transform(date,''))
}
}
Service
import {Component} from '#angular/core'
import { Injectable } from '#angular/core';
import { Http, Headers, Response, RequestOptions } from '#angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Networks } from '../../networks/wedoshoes.networks';
#Injectable()
export class TransactionDetailsServices{
constructor(private http:Http) {
}
searchTransaction(model:any){
let requestUrl=this.generateUrl(model);
let headers = this.httpHelper(true);
let options = new RequestOptions({ headers: headers });
return this.http.get(requestUrl, options)
.map((response: Response) => response.json())
.catch((error: any) => Observable.throw(error || JSON.parse(error._body)));
}
generateUrl(model:any):any{
let requestUrl=Networks.OMS_BASE_URL+"/workshops/"+model.workshops+"/orders/payments?"+
"start_date="+model.startDate+"&end_date="+model.endDate+"&offset=0&"+"limit=200";
console.log(requestUrl);
return requestUrl;
}
httpHelper(isSecure: boolean) {
let headers = new Headers({ 'Content-Type': 'application/json', 'Accept': 'application/json' });
if (isSecure) {
headers.append("Authorization", localStorage.getItem('token'));
headers.append("X-UserID", localStorage.getItem('userId'));
}
return headers;
}
}

LoadMoreElement(){
this.loadResult=true;
console.log(this.loadResult);
this.calculateOffset();
this.findMoreTransaction(this.formOutput);
}
calculateOffset(){
this.offset=this.offset+this.limit;
}
findMoreTransaction(model:any){
this.transactionDetailsService.searchTransaction(model,this.offset,this.limit).subscribe(res=>{
console.log(res);
if(res==null){
this.alertService.success("No Record Found");
this.loading=false;
this.loadResult=false;
}
else{
if(this.transactions==null){
this.transactions=[];
this.loading=false;
}
else{
this.loadResult=false;
}
this.transactions=this.transactions.concat(res);
// this.fillTransaction();
console.log(this.transactions);
}
},
error=>{
this.alertService.error(error);
this.loading=false;
});
}
}

Related

Vue 3 props are not passed to the child element

I'm trying to pass an object to a child element as a prop, but I get an arr[0] val instead of { id: 1, name: 'General' }.
There I bind prop value, currentRoom is a const with Object.
<input-message :currentRoom="currentRoom"/>
currentRooms value is correct there and equals {id: 1, name: 'General'}.
In child element I try to get props that way:
const props = defineProps({
currentRoom: Object
});
The whole code:
container.vue
<template>
<AppLayout title="Dashboard">
<template #header>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Chat
</h2>
</template>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<message-container :room="currentRoom"/>
<input-message :currentRoom="currentRoom" :customText="'blablabla'"/>
</div>
</div>
</div>
</AppLayout>
</template>
<script setup>
import AppLayout from '../../Layouts/AppLayout.vue';
import MessageContainer from "./messageContainer.vue";
import InputMessage from "./inputMessage.vue";
import {defineComponent} from "vue";
defineComponent([
AppLayout,
MessageContainer,
InputMessage
])
let chatRooms = [];
let currentRoom = [];
let messages = [];
const getRooms = () => {
axios.get('/chat/rooms')
.then( response => {
chatRooms = response.data;
setRoom(response.data[0]);
})
.catch(error => {
console.log(error);
})
}
const setRoom = (room) => {
currentRoom = room;
// If I console.log currentRoom here, it is displayed correctly!
console.log(currentRoom)
getMessages();
}
const getMessages = () => {
axios.get('/chat/rooms/' + currentRoom.id + '/messages')
.then(response => {
messages = response.data;
})
.catch(error => {
console.log(error);
});
}
getRooms();
</script>
inputMessage.vue
<template>
<div class="relative h-10 m-1">
<div style="border-top: 1px solid #e6e6e6;" class="grid grid-cols-6">
<input
type="text"
v-model="message"
#keyup.enter="sendMessage"
placeholder="Say something..."
class="col-span-5 outline-none p-1"
/>
<button
#click="sendMessage"
class="place-self-end bg-gray-500 hover:bg-blue-700 p-1 mt-1 rounded text-white">
Send
</button>
</div>
</div>
</template>
<script setup>
const props = defineProps({
currentRoom: Object
// customText: Text
});
console.log(props.currentRoom);
</script>
UPDATE
You currentRoom data property is not reactive. So, I guess, it triggers no updates to the props. You should define it this way:
const currentRoom = reactive({});
or
const currentRoom = ref({});
In case of ref() you have then change the value of the ref like this
currentRoom.value = room;
Hope it helps.
Your currentRoom is an Array. That's why you get [] in the console, when your array is empty.
Check your axios request if you get any data at all. (Browser DevTools Network Tab)
Generally, you should pass one room item to your currentRoom prop or threat your prop as array.
Like this:
<table border=1>
<tbody>
<tr v-for="(room, index) in props.currentRoom">
<td>{{index}}</td>
<td>{{room.id}}</td>
<td>{{room.name}}</td>
</tr>
</tbody>
</table>
Here is a working playground
Just do it right way and it will work.
const { createApp, ref } = Vue;
const MyComponent = {
props: {
currentRoom : {
type: Object,
default: {}
}
},
setup(props) {
console.log(`props.currentRoom: ${JSON.stringify(props.currentRoom)}`)
},
template: `<div class="MyComponent">currentRoom: {{JSON.stringify(currentRoom)}}</div>`
}
const App = {
components: {
MyComponent
},
setup() {
const rooms = ref([]);
const addRoom = () => { rooms.value.push( {id: rooms.value.length + 1, name: 'General'} ); }
return { rooms, addRoom }
}
}
const app = createApp(App)
app.mount('#app')
.MyComponent {
border: 1px solid grey;
padding: 12px;
margin: 4px;
}
<div id="app">
App.rooms: {{rooms}}<hr/>
rooms[0]: <my-component :current-room="rooms[0]"></my-component>
rooms: <my-component v-for="room in rooms" :current-room="room"></my-component>
<button type="button" #click="addRoom()">Add Room</button>
</div>
<script src="https://unpkg.com/vue#3/dist/vue.global.prod.js"></script>

Angular 12 FormControls in nested formGroup inside of two FormArrays

I am trying to build dynamic form that has such structure:
Form
-|FormGroup
--|FormArray
---|FormGroup
----|FormControl
----|FormArray
-----|FormGroup
------|FormControl <-- Problem that I cannot bind this form control to input
------|FomrControl <-- Problem that I cannot bind this form control to input
On two specified controls I get error
Cannot find control with path: 'items -> 0 -> properties -> 1'
I just guess that it can be because something wrong with let rowItem of items.controls[i].value.properties; let j=index
Tried a lot of different sceanrious without success. For example:
let rowItem of items.controls[i].properties; let j=index
give
Property 'properties' does not exist on type 'AbstractControl'.
StackBlitz
On StackBlitz it is also not working correct.
I will be grateful for advices on how to connect those FormControl's to inputs.
Html code:
<form [formGroup]="myForm">
<div formArrayName="items">
<div *ngFor="let item of items.controls; let i=index">
<div [formGroupName]="i">
<input formControlName="word" matInput>
<div formArrayName="properties">
<div *ngFor="let rowItem of items.controls[i].value.properties; let j=index">
<div [formGroupName]="j">
<input formControlName="property" matInput>
<input formControlName="value" matInput>
</div>
</div>
<br>
</div>
<button (click)="addWordProperty(items.controls[i].value.properties)">Add property</button>
<br>
</div>
</div>
<button (click)="addWord()">Add word</button>
</div>
</form>
{{ myForm.value | json }}
Type Script Code:
import { Component} from '#angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup } from '#angular/forms';
#Component({
selector: 'app-infinitive',
templateUrl: './infinitive.component.html',
styleUrls: ['./infinitive.component.css']
})
export class InfinitiveComponent {
myForm: FormGroup;
constructor(private fb: FormBuilder) {
this.myForm = this.fb.group({
items: this.fb.array([
this.fb.group({
word: this.fb.control(''),
properties: this.fb.array([
this.fb.group({
property: this.fb.control(''),
value: this.fb.control('')
})
]),
})
])
})
}
addWordProperty(control: any) {
var items = control as FormArray;
items.push(this.fb.control(''));
}
addWord() {
var array = this.myForm.get('items') as FormArray;
array.push(this.fb.group({
word: this.fb.control(''),
properties: this.fb.array([
this.fb.group({
property: this.fb.control(''),
value: this.fb.control('')
})
]),
}));
}
get items() {
return this.myForm.get('items') as FormArray;
}
}
<form [formGroup]="myForm">
<div formArrayName="items">
<div *ngFor="let item of items.controls; let i=index">
<div [formGroupName]="i">
<input formControlName="word" matInput>
<div formArrayName="properties">
<div *ngFor="let rowItem of items.controls[i].controls['properties'].controls; let j=index">
<div [formGroupName]="j">
<input formControlName="property" matInput>
<input formControlName="value" matInput>
</div>
</div>
<br>
</div>
<button (click)="addWordProperty(items.controls[i].value.properties)">Add property</button>
<br>
</div>
</div>
<button (click)="addWord()">Add word</button>
</div>
</form>

Angular 5 - Material Snackbar not work properly

SnackBar takes up the complete page height. I don't know what the problem is, see screenshot below.
And here is my code:
agentsmanagement.component.css
button {
margin: 2px;
}
.selected{
background:lightgray;
}
.example-sidenav {
padding: 20px;
}
.example-sidenav-content {
display: flex;
height: 100%;
width: 100%;
align-items: start;
justify-content: center;
}
.btn-list {
margin: 20px;
}
mat-header-cell {
background-color:#B31B1B;
color: white;
}
agentsmanagement.component.html
<standard-page>
<div>
<form>
<div fxLayout="row">
<div fxFlex>
<h1 mat-dialog-title color="primary" fxLayoutAlign="center">
Agent Management
</h1>
</div>
<div fxFlex="25" fxLayoutAlign="start">
<mat-form-field>
<input matInput placeholder="Search">
</mat-form-field>
</div>
</div>
</form>
</div>
<div mat-dialog-content>
<div class="properties">
<div fxFlex fxLayout="row" id="list-property" fxLayoutAlign="center">
<div fxFlex="95" fxLayout="column" fxLayoutAlign="none" class="mat-elevation-z8">
<mat-table #table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="{{column.id}}" *ngFor="let column of columnNames">
<mat-header-cell *matHeaderCellDef mat-sort-header>
{{column.value}}
</mat-header-cell>
<mat-cell *matCellDef="let element"> {{element[column.id]}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="agentInfo"></mat-header-row>
<mat-row *matRowDef="let row; columns: agentInfo;" [ngClass]="{ 'selected': selection.isSelected(row)}"
(click)="selection.toggle(row)"></mat-row>
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>
</div>
<div fxFlex="10" fxLayout="column" fxLayoutAlign="none" class="btn-action">
<div>
<button mat-mini-fab color="primary" class="mat-elevation-z4" (click)="showAddAgent()">
<mat-icon class="icon">add</mat-icon>
</button>
</div>
<div>
<button mat-mini-fab color="primary" class="mat-elevation-z4" (click)="showEditAgent()">
<mat-icon class="icon">create</mat-icon>
</button>
</div>
<div>
<button mat-mini-fab color="accent" class="mat-elevation-z4" (click)="showDeleteAgent()">
<mat-icon class="icon">delete</mat-icon>
</button>
</div>
</div>
</div>
</div>
</standard-page>
agentsmanagement.component.ts
import { Component, OnInit, ViewChild } from '#angular/core';
import {
MatTableDataSource, MatSort,
MatDialog, MatDialogRef,
MatSnackBar, MatPaginator,
Sort
} from '#angular/material';
import { SelectionModel } from '#angular/cdk/collections';
import { PopupAgentComponent } from "../dialogs/popup-agent/popup-agent.component";
#Component({
selector: 'app-agentsmanagement',
templateUrl: './agentsmanagement.component.html',
styleUrls: ['./agentsmanagement.component.css']
})
export class AgentsmanagementComponent implements OnInit {
tableArr: Element[] = [{ Code: 123153325, AgentName: 'Jun Mar', AgentType: 'Individual', Contact: '09324383919', Address: 'Kasambagan, Cebu', Email: 'Jun#gmail.com' },
{ Code: 123153325, AgentName: 'Jay Jay', AgentType: 'Individual', Contact: '09324383919', Address: 'Kasambagan, Cebu', Email: 'Jun#gmail.com' },
{ Code: 123153325, AgentName: 'Paano Mo Nasabi', AgentType: 'Individual', Contact: '09324383919', Address: 'Kasambagan, Cebu', Email: '' },
{ Code: 123153325, AgentName: 'Walang Poreber', AgentType: 'Cooperate', Contact: '09324383919', Address: 'Kasambagan, Cebu', Email: 'Jun#gmail.com' },
{ Code: 123153325, AgentName: 'Polano Decaprio', AgentType: 'Individual', Contact: '09324383919', Address: 'Kasambagan, Cebu', Email: 'Jun#gmail.com' },
{ Code: 123153325, AgentName: 'Pedodido Tak', AgentType: 'Individual', Contact: '09324383919', Address: 'Kasambagan, Cebu', Email: 'Jun#gmail.com' }
];
#ViewChild(MatSort) sort: MatSort;
#ViewChild(MatPaginator) paginator: MatPaginator;
dialogRef: MatDialogRef<PopupAgentComponent>;
data = Object.assign(this.tableArr);
selection = new SelectionModel<Element>(false, null);
agentInfo = [];
dataSource = new MatTableDataSource<Element>(this.tableArr);
columnNames = [{
id: "Code",
value: "Code"
}, {
id: "AgentName",
value: "Agent Name"
},
{
id: "AgentType",
value: "Agent Type"
},
{
id: "Contact",
value: "Contact"
},
{
id: "Address",
value: "Address"
},
{
id: "Email",
value: "Email"
}];
constructor(
public dialog: MatDialog,
public snackBar: MatSnackBar,
) {
}
ngOnInit() {
this.agentInfo = this.columnNames.map(x => x.id);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
}
openSnackBar(message: string, action: string) {
this.snackBar.open(message, action, {
duration: 2000,
});
}
showAddAgent() {
this.dialogRef = this.dialog.open(PopupAgentComponent, {
disableClose: true,
width: '680px',
height: '580px'
});
}
showEditAgent() {
if (this.selection.isEmpty()) {
this.openSnackBar("Please select one Agent to Update", "");
} else
this.dialogRef = this.dialog.open(PopupAgentComponent, {
disableClose: true,
width: '680px',
height: '580px'
});
}
showDeleteAgent() {
if (this.selection.isEmpty()) {
this.openSnackBar("Please select one Agent to Delete", "");
} else {
this.selection.selected.forEach(item => {
let index: number = this.data.findIndex(d => d === item);
this.dataSource.data.splice(index, 1);
this.dataSource = new MatTableDataSource<Element>(this.dataSource.data);
});
this.selection = new SelectionModel<Element>(true, []);
}
}
}
export interface Element {
Code: number,
AgentName: string,
AgentType: string,
Contact: string,
Address: string,
Email: string
}
What is the problem of with my SnackBar?. I've tried to fix it but it didn't work. I've tried to look at the console but it has no error.
I want it to look like the example from the Angular Material documentation:
SnackBar with proper height

cards stack using angular2 swing module in ionic 3

I'm using angular2 swing in ionic in order make swiping cards. So after building, I'm getting cards one below one not in the stack format(as they get in tinder). Can someone help me in figuring it out. why are the cards are not in stack format? Here is my code.
<div swing-stack #myswing1 [stackConfig]="stackConfig" (throwoutleft)="voteUp(false)" (throwoutright)="voteUp(true)" id="card-stack" >
<ion-card #mycards1 swing-card *ngFor="let job of jdetails">
<div >
<img src="assets/imgs/lap.jpg" (click)="openPage()" id="tagimg">
<div class="textoncard title" >{{ job.company }}</div>
<div class="textoncard subt">{{ job.jobtitle }}</div>
<div class="textoncard time">2 days ago</div>
</div>
<ion-card-content>
<table>
<tr>
<td class="label">Location</td>
<td class="des">{{ job.location }}</td>
</tr>
<tr>
<td class="label">Type</td>
<td class="des">{{ job.jobtype }}</td>
</tr>
<tr>
<td class="label">salary</td>
<td class="des">{{ job.jobtype }}</td>
</tr>
<tr>
<td class="label">Description</td>
<td class="des">{{ job.jobdescrition }}</td>
</tr>
<tr>
<td class="label">Source</td>
<td class="des"><p style="color: purple;font-weight: bold;">Monster</p></td>
</tr>
</table>
<div id="endbtn">
<ion-buttons class="ionrow">
<button ion-button icon-only clear (tap)="tapEvent($event)" [ngStyle]="{'color': buttonColor}">
<ion-icon name="ios-heart"></ion-icon>
</button>
<button ion-button icon-only clear style="color: black" id="sharebtn">
<i class="fas fa fa-share-alt custom-share"></i>
</button>
</ion-buttons>
</div>
</ion-card-content>
</ion-card>
</div>
Here is ts file
export class FeedsPage {
#ViewChild('myswing1') swingStack: SwingStackComponent;
#ViewChildren('mycards1') swingCards: QueryList<SwingCardComponent>;
stackConfig: StackConfig;
recentCard: string = '';
cards: Array<any>;
buttonColor: string = '#F2F0F4';
public press: number = 0;
jobtitletosave: string;
showdropdown: boolean = false;
searchQuery: string = '';
items: string[];
jdetails: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public modalCtrl: ModalController,
private nativePageTransitions: NativePageTransitions,
public jobdetail: JobsDataProvider
)
{
this.stackConfig = {
throwOutConfidence: (offsetX, offsetY, element: any) => {
return Math.min(Math.abs(offsetX) / (element.offsetWidth/2), 1);
},
transform: (element, x, y, r) => {
this.onItemMove(element, x, y, r);
},
throwOutDistance: (d) => {
return 800;
}
};
this.initializeItems();
}
ionViewDidLoad() {
console.log('ionViewDidLoad FeedsPage');
this.jobdetail.getJobDetails().then((data) => {
console.log(data);
this.jdetails = data;
});
}
openPage() {
let options: NativeTransitionOptions = {
direction: 'down',
duration: 100,
slowdownfactor: -1,
iosdelay: 50,
androiddelay: 50,
}
this.nativePageTransitions.fade(options);
this.navCtrl.push(JobDetailPage);
}
showAlert() {
let modal = this.modalCtrl.create(ModalPage);
modal.present();
}
ngAfterViewInit() {
// Either subscribe in controller or set in HTML
this.swingStack.throwin.subscribe((event: DragEvent) => {
event.target.style.background = '#ffffff';
});
}
onItemMove(element, x, y, r) {
let color = '';
const abs = Math.abs(x);
const min = Math.trunc(Math.min(16 * 16 - abs, 16 * 16));
const hexCode = this.decimalToHex(min, 2);
if (x > 0) {
color = '#' + hexCode + 'FF' + hexCode;
} else {
color = '#FF' + hexCode + hexCode;
}
element.style.background = color;
element.style['transform'] = `translate3d(0, 0, 0) translate(${x}px, ${y}px) rotate(${r}deg)`;
}
decimalToHex(d, padding) {
let hex = Number(d).toString(16);
const numPadding = typeof (padding) === 'undefined' || padding === null ? 2 : padding;
while (hex.length < numPadding) {
hex = '0' + hex;
}
return hex;
}
voteUp(like: boolean) {
}
tapEvent(e) {
this.press++;
if (this.press % 2 != 0 ) {
this.buttonColor = '#E24B4B';
}
else {
this.buttonColor = '#F2F0F4';
}
}
}
I want the cards
here is how I'm getting tem I want them as

ionic login button not working in android

Button is working when run on browser using ionic serve and ionic serve --lab command. I am able to login in web browser and redirected to dashboard.
When I generate .apk file and run on android device....login button is not working.
Not redirected to dashboard by click on login button with username and password.
I have tried this reference: Ionic android button not working
but still not get success...please give me any solution .
Login Template
<li class="item-content">
<div class="item-inner">
<div class="item-input">
<label class="item item-input">
<input class="style login3" type="email" name="email" placeholder="E-mail" ng-model="user.email">
</label>
</div>
</div>
</li>
<li class="item-content">
<div class="item-inner">
<div class="item-input">
<label class="item item-input">
<input class="style login3" type="password" name="password" placeholder="Password" ng-model="user.pwdForLogin">
</label>
</div>
</div>
</li>
</div>
<button ng-click="signIn(user)" >
Sign In
</button>
App.js
// State to represent Login View
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: 'LoginCtrl',
resolve: {
// controller will not be loaded until $waitForAuth resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth",
function (Auth) {
// $waitForAuth returns a promise so the resolve waits for it to complete
return Auth.$waitForAuth();
}]
}
})
Please help me....
Here I will show you a working example and you can use it for your code.
MY Custom CSS
.bgLogin{
width: 100%;
background-image: url("http://static.vecteezy.com/system/resources/previews/000/084/251/original/christmas-bokeh-vector-background.jpg");
background-size: 100% 100% !important;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
}
.login-content
{
margin-top:8%;
padding:0px 10px 0px 10px;
}
.login-content .login-form
{
margin-top:40%;
}
View/HTML
<ion-view class="bgLogin" name="login-view">
<ion-nav-bar>
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-content class="login-content">
<div class="login-form">
<label class="item item-input">
<input type="text" placeholder="Username" ng-model="data.username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="data.password">
</label>
</div>
<button class="button button-block login-button" ng-click="login()">Login</button>
</ion-content>
</ion-view>
App.js
Assuming your adding references to controller and service
var appStarter = angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']);
define state
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
})
controller for login
appControllers.controller('LoginCtrl', function($scope, $rootScope, LoginService, $ionicPopup, $state, $ionicHistory) {
$scope.data = {};
$scope.login = function() {
LoginService.loginUser($scope.data.username, $scope.data.password).success(function(data) {
$rootScope.userName = $scope.data.username.toUpperCase();
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go('app.welcome');
}).error(function(data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Please check your credentials!',
buttons: [
{
text: 'Ok',
type: 'orange-btn'
}
]
});
});
}
});
Service for login
.service('LoginService', function($q) {
return {
loginUser: function(name, pw) {
var deferred = $q.defer();
var promise = deferred.promise;
if (name.toLowerCase() == 'ens' && pw == 'ens' || name.toLowerCase() == 'adam' && pw == 'adam'|| name.toLowerCase() == 'illum' && pw == 'illum'|| name.toLowerCase() == 'test' && pw == 'test') {
deferred.resolve('Welcome ' + name + '!');
} else {
deferred.reject('Wrong credentials.');
}
promise.success = function(fn) {
promise.then(fn);
return promise;
}
promise.error = function(fn) {
promise.then(null, fn);
return promise;
}
return promise;
}
}
});

Resources