Changing CSS of dynamically loaded Angular elements - html

I have implemented ng2-image-viewer library to my image view and it's dynamically loading many HTML components. I wish to change the CSS of some of the dynamically loaded elements.
Here is what i have by default.
The HTML component of above before rendering is as follows,
<div class="image-viewer-container">
<app-image-viewer
[images]="[artURL]"
[loadOnInit]="true"
[idContainer]="'idOnHTML'"
[showOptions]="false"
>
</app-image-viewer>
</div>
The HTML component of above after rendering is as follows,
<div _ngcontent-pyx-c10="" class="image-viewer-container">
<app-image-viewer _ngcontent-pyx-c10="" _nghost-pyx-c11="" ng-reflect-id-container="idOnHTML" ng-reflect-images="http://localhost/artworks/art/" ng-reflect-load-on-init="true" ng-reflect-show-options="false">
<div _ngcontent-pyx-c11="" class="image-gallery-2" id="idOnHTML">
<div _ngcontent-pyx-c11="" class="image-container iv-container">
<div class="iv-wrap">
<div class="iv-loader" style="display: none;"></div>
<div class="iv-snap-view" style="opacity: 0; pointer-events: none;">
<div class="iv-snap-image-wrap"><img class="iv-snap-image" src="http://localhost/artworks/art/a/aagaard/rosegard.jpg" style="width: 137.062px; height: 149px;">
<div class="iv-snap-handle" style="top: 0px; left: -130.863px; width: 398.787px; height: 149px;"></div>
</div>
<div class="iv-zoom-slider">
<div class="iv-zoom-handle" style="left: 0px;"></div>
</div>
</div>
<div class="iv-image-view">
<div class="iv-image-wrap"><img class="iv-image iv-large-image" src="http://localhost/artworks/art/a/aagaard/rosegard.jpg" style="visibility: visible; width: 597px; height: 649px; left: 570px; top: 0px; max-width: none; max-height: none;"></div>
</div>
</div>
</div>
<div _ngcontent-pyx-c11="" class="inline-icon" style="background-color: rgb(1, 118, 189);">
<div _ngcontent-pyx-c11="">
<!--bindings={
"ng-reflect-ng-if": "true"
}-->
<a _ngcontent-pyx-c11="" class="image-viewer-tooltip ng-star-inserted">
<!--bindings={
"ng-reflect-ng-if": "true"
}--><span _ngcontent-pyx-c11="" class="tooltiptext filterTooltip ng-star-inserted"><span _ngcontent-pyx-c11="">Show only PDF:</span><i _ngcontent-pyx-c11="" class="material-icons">close</i></span><i _ngcontent-pyx-c11="" class="material-icons footer-icon" style="color: white;">picture_as_pdf</i></a>
</div>
<!--bindings={
"ng-reflect-ng-if": "false"
}-->
</div><i _ngcontent-pyx-c11="" class="material-icons prev">keyboard_arrow_left</i><i _ngcontent-pyx-c11="" class="material-icons next">keyboard_arrow_right</i>
<div _ngcontent-pyx-c11="" class="footer-info" style="background-color: rgb(1, 118, 189);"><span _ngcontent-pyx-c11="" id="current">1</span>/<span _ngcontent-pyx-c11="" class="total">1</span></div>
</div>
</app-image-viewer>
</div>
All i'm trying to do is apply following to the rendered HTML by simply defining them in SCSS but it's not seem to be working.
.iv-snap-view{
visibility: visible !important;
opacity: 1;
}
.image-gallery-2{
visibility: hidden;
}

As the component's style is encapsulated (You can read more about this here), you have two options:
Create a global stylesheet and add the styles needed there, or just copy the global styles into src/styles.css
Use ::ng-deep. You can find more info here
Applying the ::ng-deep pseudo-class to any CSS rule completely disables view-encapsulation for that rule. Any style with ::ng-deep applied becomes a global style. In order to scope the specified style to the current component and all its descendants, be sure to include the :host selector before ::ng-deep. If the ::ng-deep combinator is used without the :host pseudo-class selector, the style can bleed into other components.
Note: Even though the ::ng-deep is deprecated, it is not specified when it will be removed as there is no alternative for now.

Related

Styling the image inside the checkbox without class name

<div class="panel panel-line panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Meb Katmanları</h3>
<div class="panel-actions">
<mat-slide-toggle color="warn" [(ngModel)]="allMebLayers" (change)="mebToggle()"></mat-slide-toggle>
</div>
</div>
<div *ngIf="allMebLayers" class="panel-body" style="max-height: 70vh; overflow-y: auto">
<mat-selection-list *ngFor="let l of legends" style="overflow-y: hidden; overflow-x: hidden;">
<mat-checkbox>
<td class="p-5">{{l.layerName}}</td>
<td class="p-5"><img [src]="l.legend.imageData"></td>
</mat-checkbox>
</mat-selection-list>
</div>
</div>
I want to just style the image inside the checkbox. Any simple way without adding new class name ?
To style the image inside the checkbox WITHOUT a new class name, try this selector in your css document:
mat-checkbox img {
/* desired CSS properties */
}
To accomplish the styling, you could also use:
.p-5 img { ... }
If you want to only target that image for that class and not all of the mat-checkbox img elements that could also be on the same page.

angular material datepicker doesn't open in modal dialog

I have an angular material 2 date-picker implemented in a bootstrap modal form:
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{title}}</h4>
</div>
<div class="modal-body">
<div class="timeline-cal">
<input class="date-field" [mdDatepicker]="picker" placeholder="Choose a date">
<md-datepicker-toggle mdSuffix [for]="picker"></md-datepicker-toggle>
<md-datepicker #picker></md-datepicker>
</div>
<div class="modal-footer">
<button type="button" class="btn grey-btn pull-right" (click)="cancel()">Cancel</button>
</div>
</div>
</div>
However, upon clicking the button, the datepicker wouldn't open in the modal dialog itself but opens in the background. I tried this but didn't help:
.mat-datepicker-content{ z-index: 1200}
try,
::ng-deep .cdk-overlay-container {
z-index: 1200 !important;
}
Or this
/deep/ .cdk-overlay-container {
z-index: 1200 !important;
}
For me this worked:
::ng-deep .cdk-overlay-container {
position: fixed !important;
z-index: 100000 !important; /* set value you need */
}
You have to specify certain position for z-index.
Note: z-index only works on positioned elements (position:absolute,
position:relative, or position:fixed).
CSS z-index # W3Schools
Add this code in the component html file :
<style>
::ng-deep .cdk-overlay-container {
z-index: 2000;
</style>
Hope fully this will resolve the issue !!!

how to switch to another view using css class on click in angularjs using ngclass

I want to change the middle view of the current view when the links are clicked. one link is to view the iphone and the other one is to view the tablet. Default view should be iphone. Other than that anything in the view should not be changed with the click. I don't want to toggle between the views. Just load the view with the click on the link.
Below is the html code which I tried.
<div class="mobile-area">
<p>Mobile App</p>
<a class="mobile-icon current-device" href ng-click="iphoneView= !iphoneView"></a>
<a href ng-click="tabletView = !tabletView" class="tablet-icon"></a>
</div>
<div class="mobile-preview" ng-class="{'iphone': iphoneView}">
<div class="mobile-wrapper">
<div class="mobile-simulator">
<me-iphone tmp-url="{{appTemplateUrl}}"></me-iphone>
</div>
</div>
</div>
<div class="mobile-preview" ng-class="{'tablet': tabletView}">
<div class="mobile-wrapper">
<div class="mobile-simulator">
<me-tablet tmp-url="{{appTemplateUrl}}"></me-tablet>
</div>
</div>
</div>
Below is the css code.
.iphone {
position: relative;
background: url(../../../../images/iphone-bg.png) no-repeat;
width: 100%;
height: 100%;
padding-top: 58%;
border-radius: 1em;
float: none;
}
.tablet {
position: relative;
background: url(../../../../images/tablet.jpg) no-repeat;
width: 200%;
height: 100%;
padding-top: 58%;
border-radius: 1em;
float: none;
}
I tried different methods but nothing is working for me. Please tell me a way to load the views without toggling to the same html page.
Try this:
ng-class="tabletView ? 'tablet' : 'iphone'"
Default will be iphone. You don't need second iphoneView variable at all (if you have just these 2 views).
Try this?
<div class="mobile-area">
<p>Mobile App</p>
<a class="mobile-icon current-device" href ng-click="iphoneView=true;tabletView=false"></a>
<a href ng-click="tabletView=true;iphoneView=false" class="tablet-icon"></a>
</div>
<div class="mobile-preview" ng-class="{'iphone': iphoneView, 'tablet': tabletView}">
<div class="mobile-wrapper">
<div class="mobile-simulator">
<me-iphone ng-show="iphoneView" tmp-url="{{appTemplateUrl}}"></me-iphone>
<me-tablet ng-show="tabletView" tmp-url="{{appTemplateUrl}}"></me-tablet>
</div>
</div>
</div>
EDIT: according to karaxuna's answer, you can use just one variable
<div class="mobile-area">
<p>Mobile App</p>
<a class="mobile-icon current-device" href ng-click="tabletView=false"></a>
<a href ng-click="tabletView=true" class="tablet-icon"></a>
</div>
<div class="mobile-preview" ng-class="tabletView ? 'tablet' : 'iphone'">
<div class="mobile-wrapper">
<div class="mobile-simulator">
<me-iphone ng-show="!tabletView" tmp-url="{{appTemplateUrl}}"></me-iphone>
<me-tablet ng-show="tabletView" tmp-url="{{appTemplateUrl}}"></me-tablet>
</div>
</div>
</div>

How to locate element inside css footer

There are 2 text on page "ok" and "oops" one is under <footer> another under class=> 'meta'.
I want to verify footer text and I am using
span(:alert){div_element(:class => 'application').div_element(:class => 'txt').span_element(:class => 'app-text')}
but its verifying with meta "class" text "oops" as both have same div path.
How I can locate the span class "app-txt" inside footer specific?
<footer>
<div class="application" style="opacity: 1;">
<div class="txt" style="background-color: transparent;">
<span class="app-txt" style="background-color: transparent;">ok</span>
</div>
</div>
</footer>
<div class="meta">
<div class="application" style="opacity: 1;">
<div class="txt" style="background-color: transparent;">
<span class="app-txt" style="background-color: transparent;">oops</span>
</div>
</div>
</div>
To locate the ok use:
footer .app-txt
To locate the oops use:
.meta .app-txt
footer .app-txt {color: red;}
.meta .app-txt {color: orange;}
<footer>
<div class="application" style="opacity: 1;">
<div class="txt" style="background-color: transparent;">
<span class="app-txt" style="background-color: transparent;">ok</span>
</div>
</div>
</footer>
<div class="meta">
<div class="application" style="opacity: 1;">
<div class="txt" style="background-color: transparent;">
<span class="app-txt" style="background-color: transparent;">oops</span>
</div>
</div>
</div>
Given that you know that the two spans can be differentiated based on their ancestor element, ie the <footer> vs the <div class="meta">, you should include that in your locator.
Solution 1 - Using Nested Locators
The page object could be:
class MyPage
include PageObject
# The span in the footer
span(:in_footer) { footer_element.span_element(class: 'app-txt') }
# The span in the meta div
span(:in_meta) { div_element(class: 'meta').span_element(class: 'app-txt') }
end
As you can see, by including the differentiating ancestor element, ie the footer_element vs the div_element(class: 'meta'), you can get both texts:
p page.in_footer
#=> "ok"
p page.in_meta
#=> "oops"
Solution 2 - Using CSS-Selectors
Alternatively, depending on your comfort with CSS-selectors (or XPath), you could shorten the page object by using the CSS-selectors mentioned by #K.RajaSekharReddy or #PraveenKumar.
Using the CSS-selectors, the page object could be:
class MyPage
include PageObject
span(:in_footer, :css => 'footer .app-txt')
span(:in_meta, :css => '.meta .app-txt')
end
To locate the ok use:
footer >.application >.txt >span.app-txt {
color: blue;
}
or
footer >span.app-txt {
color: blue;
}
To locate the oops use:
.meta >.application >.txt >span.app-txt {
color: orange;
}
or
.meta >span.app-txt {
color: orange;
}

Ionic subheader bar overlapping content

In a view with header and subheader, subheader content overlaps the contents of the view.
Header in slide menu
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left" ng-hide="$exposeAside.active"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
Subheader in a view
<ion-header-bar align-title="center" class="bar bar-subheader custom bar-energized" ng-if="datos.subTitulo">
<div class="buttons">
<a class="ion-chevron-left" href="#/app/ranking/ubicacion/{{datos.divAnt}}" ng-if="datos.divAnt"></a>
</div>
<h2 class="subtitle">{{datos.subTitulo}}</h2>
<div class="buttons">
<a class="ion-chevron-right" href="#/app/ranking/ubicacion/{{datos.divSig}}" ng-if="datos.divSig"></a>
</div>
</ion-header-bar>
Div buttons in subheader overlapping content, h2 show 100%.
Something is missing in this code? Thanks
[EDIT]
Rewrote the code to suit my needs: subheader smaller than the header with two links in the corners and a title.
<ion-header-bar align-title="center" class="bar-subheader subheader_custom bar-energized">
<div class="button button-clear">
<a class="icon ion-ios-arrow-back blanco" href="#/app/ranking/ubicacion/{{datos.divAnt}}" ng-if="datos.divAnt"></a>
</div>
<div class="h2 title title_custom">{{datos.subTitulo}}</div>
<div class="button button-clear">
<a class="icon ion-ios-arrow-forward blanco" href="#/app/ranking/ubicacion/{{datos.divSig}}" ng-if="datos.divSig"></a>
</div>
</ion-header-bar>
Add this css:
.has-subheader {
top: 70px;
}
.bar-subheader.subheader_custom {
display: block;
height: 26px;
top: 44px;
}
.title.title_custom {
font-size: 16px;
font-weight: 300;
height: 20px;
left: 0;
line-height: 20px;
margin: 2px 10px 2px 10px;
min-width: 24px;
overflow: hidden;
position: absolute;
right: 0;
text-align: center;
text-overflow: ellipsis;
top: 0;
white-space: nowrap;
z-index: 0;
}
Even buttons are not in line with the subheader title. Any ideas?
New status:
Make sure that the content view knows it needs to leave space for the subheaders by adding the CSS class has-subheader:
<ion-content class="has-header has-subheader">
</ion-content>
See http://ionicframework.com/docs/components/#subheader
If you face this issue in Android, then use the following
.platform-android .bar-subheader {
top: 93px;
}
https://forum.ionicframework.com/t/sub-header-not-showing-on-android-with-tabs/15341/18
You can easily change the height of the subheader, footer, and subfooter if you are using SASS with Ionic. If you want a 70px tall subheader simply add $bar-subheader-height: 70px; to your ionic.app.scss file. Your scss file should look something similar to:
// The path for our ionicons font files, relative to the built CSS in www/css
$ionicons-font-path: "../lib/ionic/fonts" !default;
$bar-subheader-height: 70px;
// Include all of Ionic
#import "www/lib/ionic/scss/ionic";
Check out the www/lib/ionic/scss/_variables.scss file for some of the other things you can change easily.
Here are instructions for setting up sass with ionic and here is a quick tutorial.
You can add has-header or has-subheader class to your main content in ion-content directive.
Here's my code:
<ion-view view-title="View Title">
<ion-content>
<div class="bar bar-header">
<h2 class="title">Sub Header</h2>
</div>
<div class="list has-header">
<a class="item item-icon-left" href="#">
<i class="icon ion-email"></i>
Check mail
</a>
<a class="item item-icon-left item-icon-right" href="#">
<i class="icon ion-chatbubble-working"></i>
Call Ma
<i class="icon ion-ios-telephone-outline"></i>
</a>
</div>
</ion-content>
</ion-view>
<div class="list has-header"> I add the has-header class to my list to avoid subheader overlapping