How to hide a div by clicking a button? - angularjs

In my angular.js learning project I want to hide one div and show another when I click a button.
In this code, I'd like the first div to be hidden at the click (or even destroyed?) and the second div to be shown.
Basically I want the user experience of going from page 1 to page 2 in my app.
How do I make this happen?
Index.html
<ion-content ng-controller="StartpageCtrl">
<div class="list card" id="startCard" ng-show="showstartCard">
<div class="item item-image item item-text-wrap">
Card 1
</div>
</div>
<div class="list card" id="secondCard" ng-show="showsecondCard">
<div class="item item-image item item-text-wrap">
Card 2
</div>
</div>
<button ng-click="hideCard()" class="button button-full button-calm button icon-right ion-chevron-right">
Start now
</button>
</ion-content>
controllers.js
.controller("StartpageCtrl", funcion($scope){
$scope.showstartCard = true;
$scope.showsecondCard = false;
$scope.hideCard = function() {
$scope.showstartCard = false;
$scope.showsecondCard = true;
};
});
When I run the page I see "Card 2" and nothing happens when I click the button.
What I wanted to see was "Card 1" and for it to switch to "Card 2" as I click the button...
Solved
I had forgotten to add references to controllers.js in the app.js angular.module as well as the script tag in index.html. It works fine now.

Using angular:
HTML file:
<td>Source Doc..
<div id="mydiv" ng-show="showDetails">
<div id="mydiv-container">
<div id="mydiv-content">
Close
<br>
hello
</div>
</div>
</div>
</td>
css file:
body {
height: 100%;
background-color: #F0F0F0;
font-family: Arial, sans-serif;
}
#mydiv {
width: 100%;
height: 100%;
overflow: hidden;
left: 100px;
top: 150px;
position: absolute;
opacity: 0.95;
}
#mydiv-container {
margin-left: auto;
margin-right: auto;
}
#mydiv-content {
width: 70%;
padding: 20px;
background-color: white;
border: 1px solid #6089F7;
}
a {
color: #5874BF;
text-decoration: none;
}
a:hover {
color: #112763;
}

If you are looking for toggle, then this code might help as there is no need to have any extra CSS or JS functions needed.
<button ng-click="isDetailOpen = !isDetailOpen"
ng-class="!isDetailOpen ? 'ion-ios-arrow-down' : 'ion-ios-arrow-up'"
class="button button-clear button-positive icon-right">
<span ng-show="!isDetailOpen">More Detail</span>
<span ng-show="isDetailOpen">Less Detail</span>
</button>
<div ng-show="isDetailOpen">
<p>Per ad ferri dicta, omnis laudem dicunt duo an. Ex pri solum definitiones.</p>
</div>
I figured it out while working on Angular-Ionic project.

Related

How to test Ant Design slider with Cypress?

I have a slider from Ant Design (3.23.6) which generates html:
<div className="ant-slider-rail"></div>
<div className="ant-slider-track ant-slider-track-1" style="left: 45%; right: auto; width: 55%;"></div>
<div className="ant-slider-step">
<span className="ant-slider-dot" style="left: 0%;"></span>
<span className="ant-slider-dot ant-slider-dot-active" style="left: 50%;"></span>
<span className="ant-slider-dot ant-slider-dot-active" style="left: 100%;"></span>
</div>
<div tabIndex="0" className="ant-slider-handle ant-slider-handle-1" role="slider" aria-valuemin="0"
aria-valuemax="200000" aria-valuenow="90000" aria-disabled="false"
style="left: 45%; right: auto; transform: translateX(-50%);"></div>
<div tabIndex="0" className="ant-slider-handle ant-slider-handle-2" role="slider" aria-valuemin="0"
aria-valuemax="200000" aria-valuenow="200000" aria-disabled="false"
style="left: 100%; right: auto; transform: translateX(-50%);"></div>
<div className="ant-slider-mark">
<span className="ant-slider-mark-text" style="transform: translateX(-50%); left: 0%;">0</span>
<span className="ant-slider-mark-text ant-slider-mark-text-active" style="transform: translateX(-50%); left: 50%;">
100k
</span>
<span
className="ant-slider-mark-text ant-slider-mark-text-active"
style="transform: translateX(-50%); left: 100%;"
>
200k
</span>
</div>
</div>
I am trying to move left handle to the right using Cypress 4.5.0:
cy.get('[data-cy=salarySlider]').find('.ant-slider-handle-1')
.trigger('mousedown', { which: 1 })
.trigger('mousemove', 40, 0)
.trigger('mouseup')
handle seems to be selected but there is no movement. No errors too.
Any idea?
Late answer, and for Ant Design v4 slider with marks (.ant-slider-dots) but it could help. So here is how we do it (TypeScript version) :
// helper to grab slider handles by index
const slider = (sliderDot: number): string => ` .ant-slider-dot:eq(${sliderDot})`;
it('tests Ant Design v4 slider', () => {
cy.get(slider(2)).click();
cy.get(slider(3)).click();
// now slider is set on 2-3 range
});
This could be more tricky without marks.
https://ant.design/components/slider/

Control child div css using parent div class

I have a rectangular box that can call modal when clicked. Inside the box are labels and an expand icon.
<div class="clickable-box" ng-click="openRetailerGraphDetails()" data-toggle="modal" data-target="#g-retailer-purchases-graph">
<div class="dashboardBox clearfix">
<div class="pull-left dashboardBoxLabel purchases">
<h4 class="dashboardBoxLabeltext">
{{RetailerPurchases}} RETAILER PURCHASES
</h4>
<span class="dashboardBoxLabel2">
For the current month
</span>
</div>
<img class="pull-right expand-icon" src="themes/img/dashboard/expand.svg" />
</div>
</div>
I want to change the opacity of the expand icon inside img tag from 0 to 0.7 when the whole clickable box is hovered. How can I achieve it?
Edit: Here`s the css
.clickable-box {
cursor: pointer;
}
#dashboard .expand-icon {
width: 20px;
margin-top: 13px;
margin-right: -10px;
margin-bottom: -25px;
opacity: 0;
}
You can use the :hover pseudo class:
#dashboard .clickable-box:hover img.expand-icon {
opacity: 0.7;
}
.clickable-box:hover img {
opacity: 0.7;
}
img.pull-right.expand-icon:hover {
opacity: 0.7;
}
CODEPEN DEMO

ngClick is not working on a div element

I've been stuck at this for a while, this is my generated html:
<div style="margin: 0 5px; border: 2px solid #FFFFFF; height:24px;">
<div id="activity-bar" class="padding0 margin0 ng-isolate-scope" style="width: 100%; background: rgb(179, 179, 179); position: relative; overflow: visible; height: 20px;" ng-style="thisStyle" display-sections="student.history_list" height="20" loading="loading" type="2" user-id="student.fic_student_id">
<div ng-click="console.info('working');" class="activity-section absolute-pos inline-block act-29464 task-background-3 ng-scope" style="left:0%; width:10%;height:20px;" tooltip-placement="top" tooltip-append-to-body="true" uib-tooltip="PrimaryGames: Free Games and Videos
primarygames.com (click on the bar to view)
start time: 09:40am"></div>
<div ng-click="console.info('working');" class="activity-section absolute-pos inline-block act-54094 task-background-4 ng-scope" style="left:10%; width:10%;height:20px;" tooltip-placement="top" tooltip-append-to-body="true" uib-tooltip="writing0.sumdog.com
writing0.sumdog.com (click on the bar to view)
start time: 09:45am"></div>
<div ng-click="console.info('working');" class="activity-section absolute-pos inline-block act-54094 task-background-4 ng-scope" style="left:20%; width:10.01%;height:20px;" tooltip-placement="top" tooltip-append-to-body="true" uib-tooltip="writing0.sumdog.com
writing0.sumdog.com (click on the bar to view)
start time: 09:50am"></div>
<!-- Some more divs -->
</div>
</div>
The tooltips are working but the ng-clicks are not, am i missing something?
In angular, recommended way is to call function
<div ng-click="consoleinfo('working')"
In Controller:
$scope.consoleinfo = function(message){
console.log(message);
}
DEMO

Change navigation bar position in Bootstrap3

I am new to Boot Strap 3. Working on Responsive Layout.
I have a logo centered aligned and below that a navigation bar which has few links e.g. "About Us" "Contact Us" "FAQ", etc.
My Requirement is
Above 1024 resolution the navigation bar should appear below logo in a bar.
Below 1024 resolution it should be collapsed and viewed on right hand side of logo.
Please advise.
1024px is not a breakpoint in the Bootstrap default configuration. You can customize the breakpoint of when the mobile navbar kicks in at the http://getbootstrap.com/customize/ but it affects when everything breaks down to mobile. The default is 768px. So in the un-modified Bootstrap default everything (all forms, collapse, navbar-text, and so on) has to be changed along with the max-width of same, when applicable, so that is 767px. If you don't use LESS then this is a pain.
This only works if you adjust all the CSS break the navbar at the points indicated in the paragraph above. In the Bin below, that's been done, you will need to search for 1023px and 1024px to see where those are located in your installation of Bootstrap. Make a backup. Also, when you update to 3.1.0 in a few days, you'll need to do this again unless you use LESS, which will make short work of this.
DEMO: http://jsbin.com/AsaRofuW/1/
EDIT: http://jsbin.com/AsaRofuW/1/edit
This is the HTML structure to center a logo below the navigation. It does not differ from the docs, except that it adds the image.
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="yourlink.html" class="navbar-brand">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Coca-Cola_logo.svg/800px-Coca-Cola_logo.svg.png" alt="company name">
</a>
</div><!--/.navbar-header-->
<div id="nav-collapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Anchor 1</li>
<li>Anchor 2</li>
<li>Anchor 3</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Test</li>
<li>Another link</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul><!--/.navbar-nav-->
</div><!--/.nav-collapse -->
</div><!--/.container-->
</div><!--/.navbar-->
CSS
This CSS uses the min-width 1024px. For default Boostrap 3.0.3 CSS this min-width is 768px. These add styles that differ from yours and the default bootstrap, you can remove, adjust or whatever.
/* logo container padding on right so it doesn't hit the toggle */
.navbar-brand {
text-decoration: none;
padding-right: 80px;
float: left;
width: 70%; /* adjust as needed */
}
/* logo image */
.navbar-brand img {
max-width: 100%;
min-width: 90px;
max-height: 50px;
}
/* so that the navbar has some bottom white space */
.main-page {
margin-top: 20px
}
.navbar-toggle {
position:absolute;
right:0;
top:10px;
}
#media (min-width:1024px) {
.navbar-header {
width: 100%;
text-align: center;
position: absolute;
left: 0;
bottom: -120px;
/*logo position */
}
/* hide logo after scroll past navbar height */
.showlogo {
display: none
}
.navbar-collapse {
float: left;
width: 100%;
margin: 0;
position: relative;
margin-top: -50px;
padding-top: 50px;
}
/* brand for tablet and up */
.navbar-brand {
text-align: center;
float: none;
width: 100%;
padding: 0;
}
.navbar-brand img {
max-height: 80px
}
/* centered navigation */
.nav.navbar-nav {
float: left;
background: transparent!important;
}
.nav.navbar-nav > li:not(.dropdown) > a:after {
content: "/";
display: inline-block;
padding-left: 30px;
margin-right: -30px;
}
.nav.navbar-nav > li:last-child:not(.dropdown) > a:after {
content: ""
}
.nav.navbar-nav > li.active > a,
ul.nav.navbar-nav > li.dropdown.open > a.dropdown-toggle {
background: transparent;
position: relative;
}
.nav.navbar-nav li.dropdown > ul {
left: 15px
}
.nav.navbar-nav {
clear: left;
float: left;
margin: 0;
padding: 0;
position: relative;
left: 50%;
text-align: center;
}
.nav.navbar-nav > li {
position: relative;
right: 50%;
padding-left: 15px;
padding-right: 15px;
}
.nav.navbar-nav li {
text-align: left
}
/* page styles */
.main-page {
margin-top: 150px
}
}
Note: Responsive utilities won't work inside your navbar because the media queries are changed. Lots more work to fix those, which you will need to figure out. Probably requires making two sets (about 400 more lines of CSS and isolating with a .navbar preceding the class).
Since you're new to bootstrap, I think sticking to an existing breakpoint would be wise, like you have in your example link.
Try putting the logo in your html twice, and show/hide either one with css via media queries matching that same breakpoint. See: http://bootply.com/103276.

disable cloning in angularJS drag and drop

i created an shopping cart using using angularJS drag and drop. when i drag the item from catalog to cart and drop it, it goes successfully in the cart,
the problem is when i drag and drop same item in the cart, it again accept the product and add it in the cart.
how to remove this cloning?
to access the complete code please download it from here click to download the .rar file
or here is the code of main index file
the bold code below is attachment of CSS and script you can download the same version from the .rar file above or by googling the script name.
`
<meta charset="utf-8" />
<title>Drag & Drop</title>
**<script src="js/jquery.min.js"></script>**
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js">
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.7/angular.min.js">
**<script src="angular_drag_drop/angular-dragdrop.js"></script>
<link href="assets/css/jquery-ui.css" rel="stylesheet">**
<style>
.thumbnail { height: 280px !important; }
.btn-droppable { width: 180px; height: 30px; padding-left: 4px; }
.btn-draggable { width: 160px; }
.emage { height: 215px; }
h1 { padding: .2em; margin: 0; }
#products { float:left; width: 500px; margin-right: 2em; }
#cart { width: 200px; float: left; margin-top: 1em; }
#cart ol { margin: 0; padding: 1em 0 1em 3em; }
</style>
<script>
$(function() {
$("#catalog").accordion();
});
var App = angular.module('drag-and-drop', ['ngDragDrop']);
App.controller('oneCtrl', function($scope, $timeout) {
$scope.list1 = [{'title': 'Lolcat Shirt'},{'title': 'Cheezeburger Shirt'},{'title': 'Buckit Shirt'}];
$scope.list4 = [];
$scope.hideMe = function() {
$scope.list1 = [{'title': 'Lolcat Shirt'},{'title': 'Cheezeburger Shirt'},{'title': 'Buckit Shirt'}];
return $scope.list4.length > 0;
}
});
</script>
<body ng-controller="oneCtrl">
<div id="products">
<h1 class="ui-widget-header">Products</h1>
<div id="catalog">
<h2>T-Shirts</h2>
<div data-drop="true" ng-model='list1' jqyoui-droppable="{multiple:true}">
<ul>
<li ng-repeat='item in list1' ng-show="item.title" data-drag="true" data-jqyoui-options="{revert: 'invalid', helper: 'clone'}" ng-model="list1" jqyoui-draggable="{index: {{$index}}, animate: true, placeholder: 'keep'}">{{item.title}} {{list1.length}}
</li>
</ul>
</div>
</div>
</div>
<div id="cart">
<h1 class="ui-widget-header">Shopping Cart</h1>
<div class="ui-widget-content">
<ol data-drop="true" ng-model='list4' jqyoui-droppable="{multiple:true}">
<li ng-repeat="item in list4" ng-show="item.title" data-drag="true" data-jqyoui-options="{revert: 'invalid', helper: 'clone'}" ng-model="list4" jqyoui-draggable="{index: {{$index}},animate:true}">
{{item.title}}
</li>
<li class="placeholder" ng-hide="hideMe()">
Add your items here
</li>
</ol>
</div>
</div>
</body>
</html>`
If your shopping cart is the only use-case for drag and drop, then you could tackle this by disabling dragging once the object is in the cart. You can do this by binding the draggable class to an expression which checks whether the object is in the cart.
<div ng-class="{draggable: cart.indexOf(object) != -1}"></div>
Here is a basic fiddle to show you what I mean - note, this doesn't include any dragging or dropping, but is just to highlight the class binding, and get you started.
Fiddle

Resources