Angularjs - wrong behavior when remove item from ng-repeat - javascript

In the code below I'm trying to delete rows. There are two level of rows, to remove the inner level I simply use:
$scope.remove = function(array, index, parent, parent_index){
array.splice(index, 1);
if(array.length==0){
parent.splice(parent_index, 1);
}
}
Removing the inner row is working as expected but the outter row never get deleted.
Even if i change the code to try delete the outter row only the inner row disappear which it blows my mind. What is going wrong?
$scope.remove = function(array, index, parent, parent_index){
if(array.length==1){
parent.splice(parent_index, 1);
}
}
HTML code
<v-accordion id="subNestedAccordionB">
<v-pane class="hidePane" ng-repeat="child in item.investmentProposalGrouping"
ng-init="nivel3index = $index" expanded="isExpanded" id="{{ ::child.id }}">
<v-pane-header id="{{ child.id }}-header" aria-controls="{{ child.id }}-header"
class="hide-header">
<h5>
<div class="row hide">
<div class="item-accordion sub-item item-text-wrap col col-20">
{{child.agrupacionDesc}}
</div>
<div class="col col-10"></div>
<div class="col col-10"></div>
<div class="col col-10"></div>
<div class="col col-10"></div>
<div class="col col-10">{{child.agrupacionSaldo | number:2}}</div>
<div class="col col-10">{{child.agrupacionPcrt | number:2}} %</div>
<div class="col col-10"></div>
<div class="col col-10"></div>
</div>
</h5>
</v-pane-header>
<v-pane-content id="{{ child.id }}-content" aria-labelledby="{{ child.id }}-content">
<ul>
<li ng-repeat="distrib in child.distribucion" class="li_product">
<div class="productLink">
<div class="row">
<div style="margin-top: 10px;" class="col col-20 productIndent">
{{distrib.producto.nombreProducto}}
</div>
<div style="margin-top: 10px;" class="col col-10">{{distrib.producto.reqProducto}}
</div>
<div style="margin-top: 10px;" class="col col-10">
{{distrib.producto.iLiquidezProducto}}
</div>
<div style="margin-top: 10px;" class="col col-10">{{distrib.producto.cotizacion |
number:2}}
</div>
<div style="margin-top: 10px;" class="col col-10">{{distrib.producto.numTitulos |
number:2}}
</div>
<!--<<<<<<< HEAD-->
<!--<div class="col col-10 bold" id="producto-{{distrib.producto.idProducto}}">{{distrib.saldo | number:2}}<span ng-click="modal2.show();pasarImporte(child.distribucion, $index)">O</span></div>-->
<!--<div class="col col-10">{{distrib.saldoPcrt | number:2}} %</div>-->
<!--=======-->
<div style="margin-top: 10px;"
ng-if="(isDiscreccional($parent.$parent.$parent.group.agrupacionTipo)==false)"
class="col col-10">{{distrib.saldo | number:2}}
</div>
<div ng-if="(isDiscreccional($parent.$parent.$parent.group.agrupacionTipo)==true)"
class="col col-10">
<img src="img/updown.png"
style=" margin-top: 9px;width: 15px; margin-left: 5px; float: left;"
ng-click="modal3.show();pasarImporte(child.distribucion, $index);"
value="C"/>
<input style=" float: left;width: 59%;text-align: right;"
id="producto-{{distrib.producto.idProducto}}"
ng-change="changeProductPrice(distrib.producto.idProducto)" type="number"
ng-model="distrib.saldo"/>
<span style=" float: left;margin-top: 10px;">{{distrib.producto.divisaProducto}}</span>
</div>
<!--<div ng-if="(isDiscreccional($parent.$parent.$parent.group.agrupacionTipo)==true)" class="col col-10">
<input style="float: left;width: 89%;" type="number" ng-model="distrib.saldoPcrt" disabled />
<span style="float: left;margin-top: 10px;">%</span>
</div>-->
<div style="margin-top: 10px;" class="col col-10">{{distrib.saldoPcrt | number:2}}
</div
<div style="margin-top: 10px;" style="text-align: center;" class="col col-10">
{{showaAndSaveVariation(Initials, distrib.saldo, nivel1index, nivel2index,
nivel3index, $index) | number:2}}
</div>
<!--
<div class="col col-10"><input text="text" ng-model="distrib.producto.saldo"/> €</div>
<div class="col col-10"><input text="text" ng-model="distrib.producto.saldoPcrt"/></div>-->
<!--<div class="col col-10">{{distrib.producto.comDistribucion + distrib.producto.comGestion | number:2}}</div>-->
<div style="margin-top: 10px;" class="col col-10"><img src="img/closeWindow.png"
ng-click="remove(child.distribucion, $index,item.investmentProposalGrouping, nivel3index)">
</div>
</div>
</div>
</li>
</ul>
</v-pane-content>
</v-pane>
</v-accordion>
This is the model:
{
hashKey: "object:180"
agrupacionDesc: "Alternativo"
agrupacionId: "IN"
agrupacionPcrt: 0.00014727422522060096
agrupacionSaldo: 3.05
investmentProposalGrouping:[
{
$$hashKey: "object:195"
agrupacionDesc: "Alternativo"
agrupacionId: "IN"
agrupacionPcrt: 0.00014727422522060096
agrupacionSaldo: 3.05
distribucion: [
{
$$hashKey: "object:204"
producto: Object
saldo: 3.05
saldoPcrt: 0.00014727422522060096
}
]
]
}

Related

Toggle button not working in other files except the homepage

I am making a dark theme for a website. I have put a toggle button in the footer which is loaded on every page by using <landing-footer></landing-footer>.
The problem is that the toggle doesn't work on other pages and it also resets itself without reverting the effects it has when I change page.
I am pasting my footer.html and homepage and the page I tested it on.
footer.html
<footer class="ev-md-container ev-footer ev-dark-bg">
<div class="grad-container rm-grad-pad">
<div class="row">
<div class="col l6 s12">
<h5 class="white-text">EvalAI</h5>
<p class="text-light-gray">Evaluating state of the art in AI</p>
<ul class="inline-list">
<li><a class="text-light-gray" href="https://github.com/Cloud-CV/EvalAI" target="_blank"><i class="fa fa-github"></i></a></li>
<li><a class="text-light-gray" href="https://twitter.com/project_cloudcv" target="_blank"><i class="fa fa-twitter"></i></a></li>
<li>
<div class="switch">
<label class="darktheme_text">
<input type="checkbox" id="switch" name="theme">
<span class="lever"></span>
Dark Mode
</label>
</div>
</li>
<!-- <li><a class="text-light-gray" href="#!"><i class="fa fa-facebook" target="_blank"></i></a></li> -->
</ul>
<p><a class="text-white">© CloudCV {{year}}</a></p>
</div>
<div class="col l4 offset-l0 s12">
<h5 class="white-text">Links</h5>
<ul>
<li><a class="text-light-gray" ui-sref="about-us">About Us</a></li>
<li><a class="text-light-gray" ui-sref="contact-us">Contact Us</a></li>
<li><a class="text-light-gray" ui-sref="our-team">Our Team</a></li>
<li><a class="text-light-gray" ui-sref="get-involved">Get Involved</a></li>
<li><a class="text-light-gray" ui-sref="privacy_policy">Privacy Policy</a></li>
<li><a class="text-light-gray" href="https://cloudcv.org">CloudCV Website</a></li>
</ul>
</div>
<div class="col l2 s12">
<h5 class="white-text">Stats</h5>
<ul>
<li>
<a class="github-button" href="https://github.com/Cloud-CV/EvalAI" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star Cloud-CV/EvalAI on GitHub">Star</a>
</li>
<li>
<a class="github-button" href="https://github.com/Cloud-CV/EvalAI/fork" data-icon="octicon-repo-forked" data-size="large" data-show-count="true" aria-label="Fork Cloud-CV/EvalAI on GitHub">Fork</a>
</li>
</ul>
</div>
</div>
</div>
</footer>
<script>
var checkbox = document.querySelector('input[name=theme]');
checkbox.addEventListener('change', function() {
if(this.checked) {
trans()
document.documentElement.setAttribute('data-theme', 'dark')
} else {
trans()
document.documentElement.setAttribute('data-theme', 'light')
}
})
let trans = () => {
document.documentElement.classList.add('transition');
window.setTimeout(() => {
document.documentElement.classList.remove('transition')
}, 1000)
}
</script>
landing.html
<div class="white-bg view-container flex-body">
<main-header></main-header>
<div class="content">
<!-- EvalAI into -->
<div class="grad-container">
<div class="row">
<div class="col s12 m8 l8">
<div class="grad-head">
<h3 class="text-dark-black"><strong>Evaluating state-of-the-art in AI</strong></h3>
<p class="text-med-black fs-18 w-300">EvalAI is an open source platform for evaluating and
comparing machine learning (ML) and artificial intelligence algorithms (AI) at scale.</p>
<div class="landing-buttons">
<ul class="inline-list">
<li>
<a ng-click="main.hostChallenge()" href="javascript:void(0)"
class="dark-link theme"><strong>Host Challenge</strong></a>
</li>
<li><a class="btn ev-btn-dark waves-effect waves-dark grad-btn grad-btn-dark fs-14"
ui-sref="web.challenge-main">Participate</a></li>
</ul>
<br>
<br>
</div>
</div>
</div>
</div>
</div>
<section class="ev-container ev-details text-med-black ev-super-light-bg" id="ev-scroll-down">
<div class="grad-container text-med-black ">
<div class="row">
<h4 class="w-300 center">Features</h4>
</div>
<div class="row">
<div class="col s12 m2 l2">
<img src="/dist/images/features/protocols.png" alt="" width="100%">
</div>
<div class="col s12 m4 l4">
<h5 class="w-300">Custom evaluation protocol</h5>
<p class="w-300 fs-16">We allow creation of an arbitrary number of evaluation phases
and dataset splits, compatibility using any programming language, and organizing results in
both
public and private leaderboards.</p>
</div>
<div class="col s12 m2 l2">
<img src="/dist/images/features/remote.png" alt="" width="100%">
</div>
<div class="col s12 m4 l4">
<h5 class="w-300">Remote evaluation</h5>
<p class="w-300 fs-16">Certain large-scale challenges need special compute capabilities for
evaluation. If the challenge needs extra computational power, challenge organizers can
easily add their own cluster of worker nodes to process participant submissions while we
take care of hosting the challenge, handling user submissions, and maintaining the
leaderboard.</p>
</div>
</div>
<div class="row">
<div class="col s12 m2 l2">
<img src="/dist/images/features/docker.png" alt="" width="100%">
</div>
<div class="col s12 m4 l4">
<h5 class="w-300">Evaluation inside RL environments</h5>
<p class="w-300 fs-16">EvalAI lets participants submit code for their agent in the form of
docker images which are evaluated against test environments on the evaluation server. During
evaluation, the worker fetches the image, test environment, and the model snapshot and spins
up a new container to perform evaluation.</p>
</div>
<div class="col s12 m2 l2">
<img src="/dist/images/features/cli.png" alt="" width="100%">
</div>
<div class="col s12 m4 l4">
<h5 class="w-300">CLI support</h5>
<p class="w-300 fs-16">EvalAI-CLI is designed to extend the functionality of the EvalAI web
application to your command line to make the platform more accessible and terminal-friendly.
</p>
</div>
</div>
<div class="row">
<div class="col s12 m2 l2">
<img src="/dist/images/features/portability.png" alt="" width="100%">
</div>
<div class="col s12 m4 l4">
<h5 class="w-300">Portability</h5>
<p class="w-300 fs-16">EvalAI was designed with keeping in mind scalability and portability of
such a system from the very inception of the idea. Most of the components rely heavily on
open-source technologies – Docker, Django, Node.js, and PostgreSQL.</p>
</div>
<div class="col s12 m2 l2">
<img src="/dist/images/features/faster-eval.png" alt="" width="100%">
</div>
<div class="col s12 m4 l4">
<h5 class="w-300">Faster evaluation</h5>
<p class="w-300 fs-16">We warm-up the worker nodes at start-up by importing the challenge code
and pre-loading the dataset in memory. We also split the dataset into small chunks that are
simultaneously evaluated on multiple cores. These simple tricks result in faster evaluation
and reduces the evaluation time by an order of magnitude in some cases.</p>
</div>
</div>
</div>
</section>
<section class="ev-container ev-reverse-details text-med-black " id="ev-scroll-down">
<div class="grad-container text-med-black ">
<div class="row">
<h4 class="w-300 center">Popular challenges</h4>
</div>
<div class="row">
<div class="col s12 m3 l3" ng-repeat="challenge in main.challengeList.results track by $index"
ng-if="$index < 4"><a class="ev-card-hover"
ui-sref="web.challenge-main.challenge-page({challengeId:challenge.id})">
<div class="card ev-card-panel ev-challenge-card ev-card-hover">
<div class="card-image ev-card-image">
<img class="bg-img" ng-src="{{challenge.image}}">
<span class=" ev-card-title fs-14"><span><img
ng-src="{{challenge.image}}"></span>{{challenge.title}}</span>
</div>
<div class="card-content">
<p><strong class="text-light-black fs-12">Organized by</strong>
<br>
<span class="w-300 fs-16">{{challenge.creator.team_name}}</span>
</p>
<p><strong class="text-light-black fs-12">Starts on</strong>
<br>
<span class="w-300 fs-16">{{challenge.start_date | date:'medium'}}</span>
</p>
<p><strong class="text-light-black fs-12">Ends on</strong>
<br>
<span class="w-300 fs-16">{{challenge.end_date | date:'medium'}}</span>
</p>
</div>
<div class=" btn-card-detail waves-effect waves-dark w-300 fs-14"> <strong>View Details
</strong> </div>
</div>
</a>
</div>
<div ng-if="!main.challengeList.count" class="row">
<p class="text-dark-black w-300 center fs-16">Sorry! there are no featured challenges. Please
check again later.</p>
</div>
</div>
</div>
</section>
<!-- organizatons section -->
<section class="ev-container ev-reverse-details text-med-black ev-super-light-bg " id="ev-scroll-down">
<div class="grad-container text-med-black ">
<div class="row">
<div class="col s12 m12 l12">
<div class="row">
<h4 class="w-300 center">Partner Organizations</h4>
</div>
<div class="row">
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/aptiv.png" id="aptiv-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/cmu.png" id="cmu-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/draper.png" id="draper-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/ebay.png" id="ebay-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/fb.png" id="fb-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/gt.png" id="gt-logo">
</div>
</div>
</div>
<div class="row">
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/google.png" id="google-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/ibm.png" id="ibm-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/illinois.png" id="uiuc-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/iitm.png" id="iitm-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/intel.png" id="intel-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/ju.png" id="ju-logo">
</div>
</div>
</div>
<div class="row">
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/mapillary.png" id="mapillary-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/mit.png" id="mit-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/nu.png" id="nu-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/siop.png" id="siop-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/stanford.png" id="stanford-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/adelaide.png" id="adelaide-logo">
</div>
</div>
</div>
<div class="row">
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/umbc.png" id="umbc-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/pitt.png" id="pitt-logo">
</div>
</div>
<div class="col s12 l2">
<div class="org-logo">
<img src="dist/images/organizations/vt.png" id=vt-logo>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Arxiv Entry -->
<section class="ev-container ev-reverse-details text-med-black " id="ev-scroll-down">
<div class="grad-container text-med-black ">
<div class="row">
<h4 class="w-300 center">Cite our work</h4>
</div>
<div class="row">
<div class="col s12 m12 l12">
<h5 class="w-400">EvalAI: Towards Better Evaluation Systems for AI Agents</h5>
<span class="w-300 fs-16">Deshraj Yadav, Rishabh Jain, Harsh Agrawal, Prithvijit Chattopadhyay,
Taranjeet Singh, Akash Jain, Shiv Baran Singh, Stefan Lee, Dhruv Batra</span>
</div>
</div>
<div class="row">
<a href="https://arxiv.org/abs/1902.03570" target="_blank">
<img src="dist/images/evalai-paper.jpg" alt="" width="100%" class="thumb">
</a>
</div>
</div>
</section>
</div>
<landing-footer></landing-footer>
page i tested(challenge-page.html)
<div class="white-bg view-container flex-body">
<main-header></main-header>
<div class="content">
<div class="grad-container grad-vh">
<div class="col s12 m6 ">
<section class="ev-sm-container ev-view challenge-container">
<div class="ev-md-container ev-card-panel ev-z-depth-5 challenge-title-container ">
<div class="row">
<div class="col s12 m3 l2">
<div class="image-container">
<img src="{{featured_challenge.page.image}}" width="100%">
</div>
</div>
<div class="col m9 l10">
<div class="card-content">
<p><span class="fs-18"><strong>{{featured_challenge.page.title}}</strong></span>
<br>
<span ng-if="featured_challenge.page.creator.team_url != ''"><strong class="text-light-black">Organized by:</strong><a class="orange-text" href="{{featured_challenge.page.creator.team_url}}" target="_blank"> {{featured_challenge.page.creator.team_name}} </a></span>
<span ng-if="featured_challenge.page.creator.team_url == ''"><strong class="text-light-black">Organized by:</strong> {{featured_challenge.page.creator.team_name}} </span>
</p>
</div>
</div>
</div>
<div class="row rm-row-bot">
<div class="col s12">
<ul class="inline-list rm-gut">
<li><a ui-sref=".overview" ui-sref-active="active-challenge" class="text-light-black w-500"><i class="fa fa-info"></i> Overview</a></li>
<li><a ui-sref=".evaluation" ui-sref-active="active-challenge" class="text-light-black w-500"><i class="fa fa-bar-chart-o"></i> Evaluation</a></li>
<li><a ui-sref=".phases" ui-sref-active="active-challenge" class="text-light-black w-500"><i class="fa fa-level-up"></i> Phases</a></li>
<li ng-if="!featured_challenge.isParticipated"><a ui-sref=".participate" ui-sref-active="active-challenge" class="text-light-black w-500"><i class="fa fa-free-code-camp"></i> Participate</a></li>
<li><a ui-sref=".leaderboard" ui-sref-active="active-challenge" class="text-light-black w-500"><i class="fa fa-th-list"></i> Leaderboard</a></li>
</ul>
</div>
</div>
</div>
</section>
<ui-view></ui-view>
</div>
</div>
</div>
<landing-footer></landing-footer>
As per the script writtin in the footer it should add data-theme = 'dark' in html . i do it in the main landing page . but it is not working in other pages .

Showing/Hiding Box inside ngFOR

I'm trying to show/hide boxes inside a ngFor but I'm getting an error. The first item works well, but the second one I get a undefined error.
ERROR TypeError: Cannot read property 'nativeElement' of undefined
at CardComponent.push../src/app/shared/card/card.component.ts.CardComponent.showBox (card.component.ts:78)
Main HTML
<div class="col s12 l6 xl4" *ngFor="let student of students | async; let i = index">
<app-card [student]="student" [i]="i"></app-card>
</div>
card component HTML
<div class="card card-min">
<div class="card-content no-padding">
<!-- HEADER -->
<div class="card-header">
<div class="col s12 no-padding">
<div class="card travel-info col s12 no-padding" style="top:0!important; left:0!important; display: none;"
#travelInfoBox>
<p>{{ i }}</p>
</div>
<div class="col s12 m6 l6 no-padding" (click)="showBox(student.studentID, i)">
<div class="arr-dep-btn-outline">
<div class="icon i-outline">
<i class="material-icons small">flight_land</i>
</div>
<div class="txt">
<p class="arr-dep-flag" *ngIf="!isPast">Arrival</p>
<p class="arr-dep-flag" *ngIf="isPast">Arrived</p>
<p class="date-stamp">{{ student.dateArrival | date }}</p>
</div>
<div class="chev" *ngIf="!isPast">
<i class="material-icons small">chevron_right</i>
</div>
</div>
</div>
<div class="col s12 m6 l6 no-padding" (click)="showBox(student.studentID, i)">
<div class="arr-dep-btn-outline">
<div class="icon i-outline">
<i class="material-icons small">flight_takeoff</i>
</div>
<div class="txt">
<p class="arr-dep-flag" *ngIf="!isPast">Departure</p>
<p class="arr-dep-flag" *ngIf="isPast">Departured</p>
<p class="date-stamp">{{ student.dateDeparture | date }}</p>
</div>
<div class="chev" *ngIf="!isPast">
<i class="material-icons small">chevron_right</i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
card.component.ts
#ViewChildren('travelInfoBox') travelInfoBox: QueryList<ElementRef>;
showBox(studentID, i) {
const nel = this.travelInfoBox.toArray();
const nativeElement = nel[i].nativeElement;
nativeElement.style.display = nativeElement.style.display === 'none' || !nativeElement.style.display ? 'block' : 'none';
this.getData(studentID);
}
EDIT
card.component.ts
#ViewChild('travelInfoBox', { read: ElementRef }) private travelInfoBox: ElementRef;
showBox(studentID) {
const nativeElement = this.travelInfoBox.nativeElement;
nativeElement.style.display = nativeElement.style.display ? 'block' : 'none';
this.getData(studentID);
}
html
<div class="card travel-info col s12 no-padding" style="top:0!important; left:0!important; display: none;" #travelInfoBox>
<router-outlet></router-outlet>
</div>

Expand, collapse function with jquery

I have 4 columns in 1 pages, each have a button to do function to collapse/expand the div and hide the others column.
Click the button again will move the page to the initial state. The flow is:
| Col 1 | Col2 | Col3 | Col4 |
| Btn1 | btn2 | btn3 | btn4 |
When i click btn2 for example the page becomes:
| Col 2 | (width = 100%)
| Btn 2 |
How can i do that with jquery
The HTML code here:
<div class="block-panel col s3">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn1</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE
</div>
</div>
<div class="block-panel col s3">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn2</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE
</div>
</div>
<div class="block-panel col s3">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn3</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE
</div>
</div>
<div class="block-panel col s3">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn4</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE
</div>
</div>
This is how I would do it. Adding and removing classes that hide the parts that you want and showing the parts you want. Good luck.
$(".btn").on("click", function(){
if($(this).closest(".block-panel").hasClass("showSingle")){
$(".block-panel").removeClass("hidden");
$(".block-panel").removeClass("showSingle");
$(".block-panel").addClass("showAll");
} else {
$(".block-panel").removeClass("showAll");
$(".block-panel").removeClass("showSingle");
$(".block-panel").addClass("hidden");
$(this).closest(".block-panel").addClass("showSingle");
}
});
.btn {
background: #CCC;
}
.btn:hover {
cursor: pointer;
}
.hidden {
display: none;
}
.showSingle {
display: block;
float: left;
width: 100%;
outline: 1px dashed #CCC;
}
.showAll {
display: block;
float: left;
width: 25%;
outline: 1px dashed #CCC;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="block-panel col s3 showAll">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn1</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE 1
</div>
</div>
<div class="block-panel col s3 showAll">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn2</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE 2
</div>
</div>
<div class="block-panel col s3 showAll">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn3</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE 3
</div>
</div>
<div class="block-panel col s3 showAll">
<div class="col s12 headding-panel">
<div class="col s10">
abcxyz
</div>
<div class="col s2">
<a class="waves-effect waves-light btn">btn4</a>
</div>
</div>
<div class="block-panel-body">
CONTENT GOES HERE 4
</div>
</div>

Div Button hide not working properly in this code

Here i have two row, in that two row i have two button.
First Button
<button class="button button4 prlstbtn changedBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','')" style="padding-left: 0px;padding-right: 0px;display: none">Viewed</button>
Second Button
<button class="button button4 prlstbtn changeBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','')" style="padding-left: 0px;padding-right: 0px;">
Contact
Bulider</button>
My requirement is suppose i clicked the Contact Bulider button means i want hide this button ,i want to show Viewed button.
function checkvalidlogin(property_id, postedCustomerId, fullName, contactNumber, house, sublocality, emailId, excat_address) {
var $list = $(this).closest(".prptylsttNew ");
id = $list.find(".changeBTN").hide();
console.log(id)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="row box adjust prptylsttNew rentLoopListing" style=" margin-left:15px;margin-right:9px;padding: 10px;background-color:#fff;">
<div class="col-md-4 mgb">
<img src="uploads/toletlist.jpg" class="img-thumbnail" height="150" width="100%" alt="No Image" onclick="rentlist_loginnn('10')">
</div>
<div class="col-md-8" style="text-align: -webkit-center;">
<div style="background-color: #fff;padding: 12px;">
<h4 style="margin-top: 0px;" class="hov">1 RK Apartment for Rent in Marathahalli</h4>
<input type="hidden" value="10" class="propertyId">
</div>
<hr style="margin-top: 0px;margin-bottom: 0px;border-color: rgba(0, 0, 0, 0.23);">
<div style="background-color:#fff;padding:12px;">
<div class="row">
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">Rent: <span><i class="fa fa-inr" aria-hidden="true"></i></span> 7976 </h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;"> Fully-Furnished</h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">-Square feet </h5>
</div>
</div>
</div>
<div class="row prptylstt">
<div class="col-md-5 col-sm-6 col-xs-6">
<button class="button button3"> View Details</button>
</div>
<div class="col-md-1"> </div>
<div class="col-md-6 col-sm-6 col-xs-6">
<button class="button button4 prlstbtn changedBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','')" style="padding-left: 0px;padding-right: 0px;display: none">Viewed</button>
<button class="button button4 prlstbtn changeBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','')" style="padding-left: 0px;padding-right: 0px;">
Contact
Bulider</button>
</div>
</div>
</div>
</div>
<div class="row box adjust prptylsttNew rentLoopListing" style=" margin-left:15px;margin-right:9px;padding: 10px;background-color:#fff;">
<div class="col-md-4 mgb">
<img src="uploads/toletlist.jpg" class="img-thumbnail" height="150" width="100%" alt="No Image" onclick="rentlist_loginnn('9')">
</div>
<div class="col-md-8" style="text-align: -webkit-center;">
<div style="background-color: #fff;padding: 12px;">
<h4 style="margin-top: 0px;" class="hov">2 BHK Individual House for Rent in Marathahalli</h4>
<input type="hidden" value="9" class="propertyId">
</div>
<hr style="margin-top: 0px;margin-bottom: 0px;border-color: rgba(0, 0, 0, 0.23);">
<div style="background-color:#fff;padding:12px;">
<div class="row">
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">Rent: <span><i class="fa fa-inr" aria-hidden="true"></i></span> 8000 </h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;"> Semi-Furnished</h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">-Square feet </h5>
</div>
</div>
</div>
<div class="row prptylstt">
<div class="col-md-5 col-sm-6 col-xs-6">
<button class="button button3"> View Details</button>
</div>
<div class="col-md-1"> </div>
<div class="col-md-6 col-sm-6 col-xs-6">
<button class="button button4 prlstbtn changedBTN" onclick="checkvalidlogin('9','7','Sarvan','8277904354','',' Lakshmi Layout','....#gmail.com','')" style="padding-left: 0px;padding-right: 0px;display: none">Viewed</button>
<button class="button button4 prlstbtn changeBTN" onclick="checkvalidlogin('9','7','Sarvan','8277904354','',' Lakshmi Layout','....#gmail.com','')" style="padding-left: 0px;padding-right: 0px;">
Contact
Bulider</button>
</div>
</div>
</div>
</div>
The problem is that var $list = $(this) the code dont know what this refers to.
I've changed your function to this:
function checkvalidlogin(property_id, postedCustomerId, fullName, contactNumber, house, sublocality, emailId, excat_address, obj) {
var $list = $(obj).parents(".prptylsttNew");
$list.find(".changeBTN").hide();
}
Now your buttons look like:
<button class="button button4 prlstbtn changedBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','', this)" style="padding-left: 0px;padding-right: 0px;display: none">Viewed</button>
Added this to the end of your click event
'...#gmail.com','', this)
^^^^
function checkvalidlogin(property_id, postedCustomerId, fullName, contactNumber, house, sublocality, emailId, excat_address, obj) {
var $list = $(obj).parents(".prptylsttNew");
$list.find(".changeBTN").hide();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row box adjust prptylsttNew rentLoopListing" style=" margin-left:15px;margin-right:9px;padding: 10px;background-color:#fff;">
<div class="col-md-4 mgb">
<img src="uploads/toletlist.jpg" class="img-thumbnail" height="150" width="100%" alt="No Image" onclick="rentlist_loginnn('10')">
</div>
<div class="col-md-8" style="text-align: -webkit-center;">
<div style="background-color: #fff;padding: 12px;">
<h4 style="margin-top: 0px;" class="hov">1 RK Apartment for Rent in Marathahalli</h4>
<input type="hidden" value="10" class="propertyId">
</div>
<hr style="margin-top: 0px;margin-bottom: 0px;border-color: rgba(0, 0, 0, 0.23);">
<div style="background-color:#fff;padding:12px;">
<div class="row">
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">Rent: <span><i class="fa fa-inr" aria-hidden="true"></i></span> 7976 </h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;"> Fully-Furnished</h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">-Square feet </h5>
</div>
</div>
</div>
<div class="row prptylstt">
<div class="col-md-5 col-sm-6 col-xs-6">
<button class="button button3"> View Details</button>
</div>
<div class="col-md-1"> </div>
<div class="col-md-6 col-sm-6 col-xs-6">
<button class="button button4 prlstbtn changedBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','', this)" style="padding-left: 0px;padding-right: 0px;display: none">Viewed</button>
<button class="button button4 prlstbtn changeBTN" onclick="checkvalidlogin('10','0','Raju','9090909090','',' Lakshmi Layout','....#gmail.com','', this)" style="padding-left: 0px;padding-right: 0px;">
Contact
Bulider</button>
</div>
</div>
</div>
</div>
<div class="row box adjust prptylsttNew rentLoopListing" style=" margin-left:15px;margin-right:9px;padding: 10px;background-color:#fff;">
<div class="col-md-4 mgb">
<img src="uploads/toletlist.jpg" class="img-thumbnail" height="150" width="100%" alt="No Image" onclick="rentlist_loginnn('9')">
</div>
<div class="col-md-8" style="text-align: -webkit-center;">
<div style="background-color: #fff;padding: 12px;">
<h4 style="margin-top: 0px;" class="hov">2 BHK Individual House for Rent in Marathahalli</h4>
<input type="hidden" value="9" class="propertyId">
</div>
<hr style="margin-top: 0px;margin-bottom: 0px;border-color: rgba(0, 0, 0, 0.23);">
<div style="background-color:#fff;padding:12px;">
<div class="row">
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">Rent: <span><i class="fa fa-inr" aria-hidden="true"></i></span> 8000 </h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;"> Semi-Furnished</h5>
</div>
<div class="col-md-4" style="padding-left: 0px;padding-right: 0px;">
<h5 style="margin-top: 0px;">-Square feet </h5>
</div>
</div>
</div>
<div class="row prptylstt">
<div class="col-md-5 col-sm-6 col-xs-6">
<button class="button button3"> View Details</button>
</div>
<div class="col-md-1"> </div>
<div class="col-md-6 col-sm-6 col-xs-6">
<button class="button button4 prlstbtn changedBTN" onclick="checkvalidlogin('9','7','Sarvan','8277904354','',' Lakshmi Layout','....#gmail.com','', this)" style="padding-left: 0px;padding-right: 0px;display: none">Viewed</button>
<button class="button button4 prlstbtn changeBTN" onclick="checkvalidlogin('9','7','Sarvan','8277904354','',' Lakshmi Layout','....#gmail.com','', this)" style="padding-left: 0px;padding-right: 0px;">
Contact
Bulider</button>
</div>
</div>
</div>
</div>

Show / Hide Nested Divs inside ng-repeat

I have a div with sub divs to create a nested grid system.
There are three levels in total:
MainDiv - Always Visible
SecondDiv - Show or hide when clicked on MainDiv
ThirdDiv - Show or hide when clicked on SecondDiv
<div class="container padding" style="background-color: #fff;" ng-controller="MyCtrl">
<div class="row">
<div class="col col-75" >
Department / Product Type
</div>
<div class="col col-25">
Qty
</div>
</div>
<div ng-repeat="item in departments | orderBy:'-qty'" style="padding:0px;margin: 0;">
<div class="row" ng-class-odd="'odd'" ng-class-even="'even'">
<div class="col col-75" style="padding:0;margin:0;">
{{item.departmentName}} - {{item.productTypeName}} - Need Click here
</div>
<div class="col col-25" align="center" valign="middle" style="font-size: 14px;font-weight:bold;padding:0;margin:0;">
{{item.qty}}
</div>
</div>
<div ng-repeat="style in item.styles" style="padding:0;margin: 0;">
<div class="row">
<div class="col" style="margin-left: 5% !important;border-top-width:0;border-bottom-width:0;">
{{style.styleNum}} ({{style.qty}}) - Need Click here
</div>
</div>
<div class="row" ng-attr-id="{{ 'level-2-' + $index }}">
<div class="col col-5" style="border:0"></div>
<div class="col col-5" style="border-left:0;border-bottom:0;border-right:0;"></div>
<div class="col col-25">Color</div>
<div class="col col-25">Size</div>
<div class="col">Product#</div>
</div>
<div ng-repeat="styleLine in style.details">
<div class="row">
<div class="col col-10" style="border:0;"></div>
<div class="col col-25">{{styleLine.color}}</div>
<div class="col col-25">{{styleLine.size}}</div>
<div class="col">{{styleLine.productNum}}</div>
</div>
</div>
</div>
</div>
</div>
Now I need to add a click event on the div to show hide the necessary nested divs.
Plunker: http://plnkr.co/z3RiV6cDFC6YjrbuqxN9
Generic example using ng-init and ng-click:
<div ng-repeat="obj in items" ng-init="show = false">
<div ng-click="show = !show"></div>
<div ng-repeat="sub in obj.children" ng-show="show">
<p>Hello World!</p>
</div>
</div>

Categories

Resources