how to use loading panel with angularjs - html

I want to show the loading icon(spinner) when I hit the button the request is going from controller to server. It will take some time to respond mean while, I need to show any loading icon. Once the server respond to the controller I just want to disable the loading icon.
Html:
<div class="modal-content" style="margin-top:135px">
<div class="modal-header">
<h4 class="modal-title pull-left"> Add New Role</h4>
<button type="button" class="close pull-right"
data-dismiss="modal" aria-hidden="true" title="Close">
x
</button>
</div>
<div class="modal-body">
<div class="row" style="margin-bottom:1%">
<div class="col-xs-3">
<h6><strong>Role<span style="color:green;">*</span></strong></h6>
</div>
<div class="col-xs-9">
<input type="text" required name="RoleName" placeholder="Role Name" onkeyup="convertToUppercase(this)"
class="form-control" ng-model="Role.RoleName" ng-change="verifyRoleDuplicate()" />
</div>
</div>
<div class="row" style="margin-bottom:1%">
<div class="col-xs-3">
<h6><strong> Description</strong></h6>
</div>
<div class="col-xs-9">
<textarea name="Description"
style="width: 100%; max-height: 200px; max-width: 100%;" ng-model="Role.Description" maxlength="255"></textarea>
</div>
</div>
<div class="row" style="margin-bottom:1%">
<div class="col-xs-3">
<h6><strong>IsActive?</strong></h6>
</div>
<div class="col-xs-9">
<input type="checkbox" name="IsActive" class="form-control" ng-model="Role.IsActive" style="width:20px;" />
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="AddRole()" ng-disabled="disableds || profileformAdd.$invalid" data-dismiss="modal" title="Save">Save</button>
<button class="btn btn-primary" data-dismiss="modal" title="Cancel" >Cancel</button>
</div>
</div>
controller:
$scope.AddRole = function ()
{
$http.post('/AddNewRole', $scope.Role).then(function (response) {
//console.log(response);
$notify.success('Success', "New Role" + " '" + $scope.Role.RoleName +"' " + "is inserted Successfully");
refresh();
$scope.Role='';
})
};
when I click the add button It will open the popup, Popup has two buttons if I click save button I want to display the loading icon. after save functionality completed It should hide the loading icon.

You can use css or svg loader for the same.
Simple Example of loader is given below.
Demo: http://codepen.io/sumitridhal/pen/gWWORr
HTML
<div class="container" ng-app="myApp">
<div ng-controller="myController">
Button
<div class="loader loader--style1" title="0" ng-if="load">
<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 40 40" enable-background="new 0 0 40 40" xml:space="preserve">
<path opacity="0.2" fill="#000" d="M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946
s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634
c0-6.425,5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,26.541,26.626,31.749,20.201,31.749z"/>
<path fill="#000" d="M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0
C22.32,8.481,24.301,9.057,26.013,10.047z">
<animateTransform attributeType="xml"
attributeName="transform"
type="rotate"
from="0 20 20"
to="360 20 20"
dur="0.5s"
repeatCount="indefinite"/>
</path>
</svg>
</div>
</div>
</div>
CSS
body{
padding: 1em;
background: #2B3134;
color: #777;
text-align: center;
font-family: "Gill sans", sans-serif;
width: 80%;
margin: 0 auto;
}
h1{
margin: 1em 0;
border-bottom: 1px dashed;
padding-bottom: 1em;
font-weight: lighter;
}
p{
font-style: italic;
}
.loader{
margin: 0 0 2em;
height: 100px;
width: 20%;
text-align: center;
padding: 1em;
margin: 0 auto 1em;
display: inline-block;
vertical-align: top;
}
/*
Set the color of the icon
*/
svg path,
svg rect{
fill: #FF6700;
}
JS
(function(){
var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope, $timeout){
$scope.load = false;
$scope.toggle = function (){
$http.get(someUrl).success(function(){
$scope.load = true;
// Logic goes here
$scope.load = false;
}).error(function(){
$scope.load = true;
// Logic goes here
$scope.load = false;
})
}
});
})();

Related

Cropped SVG with Clip-path changes Height on zooming in and out [duplicate]

I wanted a cylindrical container containing liquid and this liquid changes color and its amount in that container, So I used SVG for this purpose (SVG is used for liquid in a cylindrical container).
Here is the source code along with SVG
function changeCol(col) {
document.querySelector('path').style.setProperty('fill', col, '!important');
document.querySelector('ellipse').style.setProperty('fill', col, '!important');
//Its not working I dont know why.
}
function changeHeight(vol) {
//Some Code to change its height.
}
.container {
width: fit-content;
border: solid red;
}
.liquid {
width: 200px;
}
.liquid svg * {
fill: red !important;
}
<div class="container">
<div class="liquid">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 216.66 325.25">
<title>liquid_RBt</title>
<path d="M216.66,28V297.25c0,15.47-48.5,28-108.33,28S0,312.72,0,297.25V28C0,43.46,48.5,56,108.33,56S216.66,43.46,216.66,28Z" style="fill:#fff;stroke:#fff;stroke-miterlimit:10;opacity:0.7000000000000001"/>
<ellipse cx="108.33" cy="28" rx="108.33" ry="28" style="fill:#fff;stroke:#fff;stroke-miterlimit:10;opacity:0.8"/>
</svg>
</div>
</div>
<div class="controller">
<div class="color-change">
<button class="col-btn" onclick="changeCol('red');">Red</button>
<button class="col-btn" onclick="changeCol('blue');">Blue</button>
<button class="col-btn" onclick="changeCol('green');">green</button>
</div>
<div class="change-amount">
<input type="number" id="amountInp" onchange='changeHeight(this.value)' placeholder="(in ml)">
</div>
</div>
I've clipped the path with a clipPath that I then move about to hide the parts of the polygon that need to disappear.
I don't know the volume of the cylinder either so you might want to scale the number.
I also fixed the colouring.
function changeCol(col) {
document.querySelector('path').style.setProperty('fill', col);
document.querySelector('ellipse').style.setProperty('fill', col);
}
function changeHeight(vol) {
// not sure how much 100ml is supposed to fill up
document.querySelector('ellipse').cy.baseVal.value = 300 - vol;
document.querySelector('rect').y.baseVal.value = 300-vol;
}
.container {
width: fit-content;
border: solid red;
}
.liquid {
width: 200px;
}
<div class="container">
<div class="liquid">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 216.66 325.25">
<title>liquid_RBt</title>
<defs>
<clipPath id="cp">
<rect x="0" y="0" width="230" height="400"/>
</clipPath>
</defs>
<path d="M216.66,28V297.25c0,15.47-48.5,28-108.33,28S0,312.72,0,297.25V28C0,43.46,48.5,56,108.33,56S216.66,43.46,216.66,28Z" style="fill:red;stroke:#fff;stroke-miterlimit:10;opacity:0.7000000000000001;clip-path: url(#cp)"/>
<ellipse cx="108.33" cy="28" rx="108.33" ry="28" style="fill:red;stroke:#fff;stroke-miterlimit:10"/>
</svg>
</div>
</div>
<div class="controller">
<div class="color-change">
<button class="col-btn" onclick="changeCol('red');">Red</button>
<button class="col-btn" onclick="changeCol('blue');">Blue</button>
<button class="col-btn" onclick="changeCol('green');">green</button>
</div>
<div class="change-amount">
<input type="number" id="amountInp" onchange='changeHeight(this.value)' placeholder="(in ml)">
</div>
</div>
Set the preserve aspect ratio to none.
<svg preserveAspectRatio="none" /* here are your other attributes */>

How do I display a Bootstrap 4 SVG icon in a button with a CSS class?

I am using Bootstrap 4's SVG icons in my buttons. I have the code working with the SVG hardcoded into the page's HTML. Now I want to refactor the SVG into a CSS class. I have followed the Bootstrap 4 instructions for creating the CSS class but I cannot work out how to display the icon on my button. I've tried a lot of variations without success.
CSS:
.bi::before {
display: inline-block;
content: "";
background-image: url('data:image/svg+xml,<svg width="2em" height="2em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"><path fill-rule="evenodd" d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"></svg>');
background-repeat: no-repeat;
background-size: 1rem 1rem;
}
HTML:
<a href="#" class="btn bi" role="button" download></a>
Your help is greatly appreciated.
Well, to make your code work, there is a couple of note you should consider it.
First off, the <path> element within your SVG does not have any closing tag, so it will produce an error in the data attribute and it will prevent the icon to be shown.
To make your SVG responsive friendly it and fill the available space in the container it is better to avoid using width and height directly in the SVG element and use preserveAspectRatio="none" instead.
It is better to encode your SVG element instead of putting it directly within the data:image/svg to provide a valid string format for cross browsing purposes. You can use tools like this for the cause.
According to the above notes, your final code should be something like this:
.bi::before {
content: "";
display: inline-block;
background-image: url('data:image/svg+xml,%3Csvg%20preserveAspectRatio%3D%22none%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22currentColor%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20d%3D%22M.5%209.9a.5.5%200%200%201%20.5.5v2.5a1%201%200%200%200%201%201h12a1%201%200%200%200%201-1v-2.5a.5.5%200%200%201%201%200v2.5a2%202%200%200%201-2%202H2a2%202%200%200%201-2-2v-2.5a.5.5%200%200%201%20.5-.5z%22%20%2F%3E%3Cpath%20fill-rule%3D%22evenodd%22%20d%3D%22M7.646%2011.854a.5.5%200%200%200%20.708%200l3-3a.5.5%200%200%200-.708-.708L8.5%2010.293V1.5a.5.5%200%200%200-1%200v8.793L5.354%208.146a.5.5%200%201%200-.708.708l3%203z%22%20%2F%3E%3C%2Fsvg%3E');
background-repeat: no-repeat;
width: 2rem;
height: 2rem;
}
<a href="#" class="btn bi" role="button" download></a>
NOTE: You can also create an SVG file in your project and then directly refer to it in your background image property like regular images for easier usage.
You can add an tag inside the or tag and apply the class to it. You can try to do it without the pseudoclass. Also you can adjust the icon in the button adding padding to the button.
the same question here.in my case i used this method (one of others) in my demo with my fastest php framework in the world (i use similar bootstrap buttons to change the language in the page)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="Custa">
<title>Document</title>
<style>
.flcn{ content:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL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IDIyLjNINTBMMjguNCAyMDVsOC4zIDI1LjVMMTUgMjE0LjZsLTEzIDkuNUEyNTguNSAyNTguNSAwIDAgMCAwIDI1NmgyNTZWMGMtNTAuNiAwLTk3LjcgMTQuNy0xMzcuNCA0MHptOS45IDE5MC40bC0yMS43LTE1LjgtMjEuNyAxNS44IDguMy0yNS41TDcxLjcgMTg5aDI2LjhsOC4zLTI1LjUgOC4zIDI1LjVoMjYuOGwtMjEuNyAxNiA4LjMgMjUuNXptLTguMy0xMDBsOC4zIDI1LjQtMjEuNy0xNS43LTIxLjcgMTUuNyA4LjMtMjUuNS0yMS43LTE1LjdoMjYuOGw4LjMtMjUuNiA4LjMgMjUuNmgyNi44bC0yMS43IDE1Ljd6bTEwMC4xIDEwMGwtMjEuNy0xNS44LTIxLjcgMTUuOCA4LjMtMjUuNS0yMS43LTE1LjhoMjYuOGw4LjMtMjUuNSA4LjMgMjUuNWgyNi44TDIxMiAyMDVsOC4zIDI1LjV6bS04LjMtMTAwbDguMyAyNS40LTIxLjctMTUuNy0yMS43IDE1LjcgOC4zLTI1LjUtMjEuNy0xNS43aDI2LjhsOC4zLTI1LjYgOC4zIDI1LjZoMjYuOEwyMTIgMTMwLjN6bTAtNzQuN2w4LjMgMjUuNi0yMS43LTE1LjhMMTc3IDgxLjNsOC4zLTI1LjZMMTYzLjUgNDBoMjYuOGw4LjMtMjUuNUwyMDcgNDBoMjYuOEwyMTIgNTUuN3oiLz48L3N2Zz4=); }
/*
generated by me with php $flagencoded= base64_encode($svgimageloadedfrompath);
then with echo,fwrite,content output in some other way I generate
echo '.classname1{ content:url(data:image/svg+xml;base64,'.$flagencoded.');}';
so I got what you reading up
in my case all svg files are from github: flags public domain(free to anyone to use)
*/
p{
width: 30px;
height:30px;
}
</style>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<body>
<div class="pb-3">
<div class="container">
<div class="row">
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="fles"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flfr"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flus"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flit"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flde"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flcn"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flro"></p>
</button>
</div>
<div class="col">
<button class="btn btn bg-info" type="submit">
<p class="flru"></p>
</button>
</div>
</div>
</div>
</div>
</body>
</html>

How to use svg for clip path

I'm trying to build a star rating feature, and am surprised to find that the part that's giving me the most trouble is figuring out how to get the star shape. It seems to me that the most straightforward approach, given what I have built already, is to try and use an SVG star shape to create a clip path on the div elements that show the rating. I'm familiar with clip-path in a general sense, and have used it for more basic shapes, but am struggling a lot to understand how to use it with an svg and why my current code is not working (svgs are not exactly in my typical wheelhouse).
The code:
const stars = document.getElementsByClassName('star');
function fillStars(starClasses, placeRating) {
const wholeFill = Math.floor(placeRating);
const decimalFill = placeRating % 1;
const yellowFill = decimalFill.toFixed(2).toString().replace('0.', '');
for (let i = 0; i < wholeFill; i++) {
starClasses[i].style.backgroundColor = '#fbff01';
}
if (placeRating - wholeFill !== 0) {
starClasses[starClasses.length - 1].style.background = `linear-gradient(90deg, #fbff01 ${yellowFill}%, #FFFFFF 0%)`;
}
}
fillStars(stars, 4.3);
.star {
width: 30px;
height: 30px;
border: solid 1px gray;
clip-path: url(#star-clip);
}
#rating {
display: flex;
}
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<defs>
<clipPath id="star-clip" clipPathUnits="objectBoundingBox">
<rect fill="#fff" id="canvas_background" height="40" width="41" y="-1" x="-1"/>
<rect fill="url(#gridpattern)" stroke-width="0" y="0" x="0" height="100%" width="100%"/>
<path id="svg_1" d="m3.885,14.64105l11.84103,0l3.65897,-12.22295l3.65897,12.22295l11.84103,0l-9.57958,7.55411l3.65916,12.22295l-9.57958,-7.55431l-9.57958,7.55431l3.65916,-12.22295l-9.57958,-7.55411z" stroke-width="1.5" stroke="#000" fill="#fff"/>
</clipPath>
</defs>
</svg>
<div id="header">
<div id="rating">
<div id="star-1" class="star"></div>
<div id="star-2" class="star"></div>
<div id="star-3" class="star"></div>
<div id="star-4" class="star"></div>
<div id="star-5" class="star"></div>
</div>
</div>
There's a good answer here about calculating a clipPath's 0-1 range from the original SVGs dimensions.
.star {
width: 30px;
height: 30px;
clip-path: url(#star-clip);
background: Gold;
}
#rating {
display: flex;
}
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<defs>
<clipPath id="star-clip" clipPathUnits="objectBoundingBox" transform="scale(0.025, 0.02439)">
<path d="m3.885,14.64105l11.84103,0l3.65897,-12.22295l3.65897,12.22295l11.84103,0l-9.57958,7.55411l3.65916,12.22295l-9.57958,-7.55431l-9.57958,7.55431l3.65916,-12.22295l-9.57958,-7.55411z" />
</clipPath>
</defs>
</svg>
<div id="rating">
<div id="star-1" class="star"></div>
<div id="star-2" class="star"></div>
<div id="star-3" class="star"></div>
<div id="star-4" class="star"></div>
<div id="star-5" class="star"></div>
</div>
Can you use clip-path: polygon(); ?
I think url(#id) is not fully supported or hard to get correct.
A not about the border: the border will be applied to the bounding box
see the last star
.star {
width: 50px;
height: 50px;
background-color: pink;
border: solid 1px gray;
clip-path: polygon(54.5% 24.5%, 80.25% 24.27%, 60.73% 34.91%, 75% 52.25%, 44.5% 41.24%, 15% 52.75%, 30.00% 34.75%, 1.5% 25.25%, 31.77% 24.86%, 41.82% 9.01%);
}
.star-last {
background-color: #f1e745;
height: 50px;
width: 50px;
clip-path: polygon(54.5% 24.5%, 80.25% 24.27%, 60.73% 34.91%, 75% 52.25%, 44.5% 41.24%, 15% 52.75%, 30% 34.75%, -200.42% 25.25%, 31.77% 24.86%, 41.82% 9.01%);
border: 1px solid black;
}
#rating {
display: flex;
}
<div id="header">
<div id="rating">
<div id="star-1" class="star"></div>
<div id="star-2" class="star"></div>
<div id="star-3" class="star"></div>
<div id="star-4" class="star"></div>
<div id="star-5" class="star-last"></div>
</div>
</div>
Edit: As I stated it is hard to get right with a standard SVG path, however adding the transform scale is what you need to do as pointed out in the chosen answer, something I now learnt. Below are other way to achieve the same ends but the chosen answer is the best way.
Maybe it is your path definition, as I said in my other answer url(#id) seems somewhat difficult to get right with standard SVG paths.
I copied a heart path from MDN and removed the rects and your code works.
Edit: If you can't work out correct definition syntax for a star path it is possible to use the polygon() code from CSS as decimal in place of the path in the svg.
remove <path> from svg and replace with.
<polygon points="0.545 0.245, 0.8025 0.2427, 0.6073 0.3491, 0.75 0.5225, 0.445 0.4124, 0.15 0.5275, 0.3000 0.3475, 0.15 0.2525, 0.3177 0.2486, 0.4182 0.0901" />
const stars = document.getElementsByClassName('star');
function fillStars(starClasses, placeRating) {
const wholeFill = Math.floor(placeRating);
const decimalFill = placeRating % 1;
const yellowFill = decimalFill.toFixed(2).toString().replace('0.', '');
for (let i = 0; i < wholeFill; i++) {
starClasses[i].style.backgroundColor = '#fbff01';
}
if (placeRating - wholeFill !== 0) {
starClasses[starClasses.length - 1].style.background = `linear-gradient(90deg, #fbff01 ${yellowFill}%, #FFFFFF 0%)`;
}
}
fillStars(stars, 4.3);
.star {
width: 30px;
height: 30px;
border: solid 1px gray;
clip-path: url(#star-clip);
}
#rating {
display: flex;
}
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0">
<defs>
<clipPath id="star-clip" clipPathUnits="objectBoundingBox">
<path d="M0.5,1
C 0.5,1,0,0.7,0,0.3
A 0.25,0.25,1,1,1,0.5,0.3
A 0.25,0.25,1,1,1,1,0.3
C 1,0.7,0.5,1,0.5,1 Z" ></path>
</clipPath>
</defs>
</svg>
<div id="header">
<div id="rating">
<div id="star-1" class="star"></div>
<div id="star-2" class="star"></div>
<div id="star-3" class="star"></div>
<div id="star-4" class="star"></div>
<div id="star-5" class="star"></div>
</div>
</div>

nav gap in IE11 between two elements

There is a gap between the nav bar and the HTML element below the nav bar in IE11. The styles work on Safari and Chrome. Is only on IE that it doesn't.
As you can see from the image above that a couple of pixels is added to the padding between the nav and the element below. I'm working with Sass and Tailwind. I can't find where this issue is coming from.
<div class="js-text-controller-options c-text-controller__options hidden" id="text-controls">
<div class='c-text-controller__languages'>
{% do action('icl_language_selector') %}
</div>
<div class="c-text-controller__sizer">
<em class="c-text-controller__sizer-text">
{{__('Adjust text size', 'accessnyctheme')}}
</em>
<button class="c-text-controller__sizer-btn btn-text js-text-larger">
<svg class="icon icon-ui-plus-circle">
<use xlink:href="#icon-ui-plus-circle"></use>
</svg>
<div class="sr-only">{{__('Larger', 'accessnyctheme')}}</div>
</button>
<button class="c-text-controller__sizer-btn btn-text js-text-smaller">
<svg class="icon icon-ui-minus-circle">
<use xlink:href="#icon-ui-minus-circle"></use>
</svg>
<div class="sr-only">{{__('Smaller', 'accessnyctheme')}}</div>
</button>
</div>
</div>
</div>
</div>
<nav class="o-navigation color-dark-background">
<div class="logo-access">
<a href="{{ urlBase }}/">
<svg class="icon icon-logo-full">
<use xlink:href="#icon-logo-full"></use>
</svg><span class="sr-only">{{__('Access NYC', 'accessnyctheme')}}</span>
</a>
</div>
<nav class="o-navigation__nav nav-inline print:hidden" data-js="site-desktop-nav">{% spaceless %}
<a class="screen-desktop:hidden" href="#o-mobile-nav" data-js="toggle-nav">
{{__('Menu', 'accessnyctheme')}}
</a>
{% include 'partials/nav.twig' with {this: {style: 'hidden screen-desktop:inline-block'}} %}
<a class="td-inherit js-toggle-search" href="#search">
<svg class="icon icon-ui-search">
<use xlink:href="#icon-ui-search"></use>
</svg>
{{__('Search', 'accessnyctheme')}}
</a>
{% endspaceless %}</nav>
</nav>
<div class="o-mobile-nav color-mid-background print:hidden" id="o-mobile-nav">
<a class="o-mobile-nav__close" href="#o-mobile-nav" data-js="toggle-nav">
{{__('close & return to site', 'accessnyctheme')}}
<svg class="icon icon-ui-x">
<use xlink:href="#icon-ui-x"></use>
</svg>
</a>
<div class="o-mobile-nav__inner">
<h4 class="o-mobile-nav__header">
{{__('Get help now', 'accessnyctheme')}}
</h4>
<nav class="nav-block">
{% include 'partials/nav.twig' %}
<a href="{{ urlBase }}/?s=">
<svg class="icon icon-ui-search">
<use xlink:href="#icon-ui-search"></use>
</svg>{{__('Search', 'accessnyctheme')}}
</a>
</nav>
</div>
</div>
<div class="o-search-box js-search-box print:hidden" id="search" aria-hidden="true">
<div class="o-search-box__inner">
<div class="usa-grid">
<div class="usa-width-one-whole">
<a class="o-search-box__close js-hide-search" href="#content">
<svg class="icon icon-ui-x">
<use xlink:href="#icon-ui-x"></use>
</svg><span class="sr-only">{{__('Close search', 'accessnyctheme')}}</span>
</a>
This is the HTML base.twig template. Here is the styles for the navigation bar.
/**
* Nav
*/
// Dependencies
#import 'config/fonts';
#import 'config/colors';
#import 'config/typography';
#import 'config/media';
#import 'config/direction';
#import 'config/dimensions';
// Declarations
#mixin nav-icon {
svg {
text-decoration: none;
}
.icon {
margin-#{$text-direction-end}: .3em;
vertical-align: middle;
margin-top: -2px
}
}
.nav-inline {
#include typography-nav();
list-style: none;
text-align: $text-direction-end;
flex: 1 1 auto;
margin: 0;
padding: 0;
a {
display: inline-block;
margin-#{$text-direction-start}: 1em;
}
.active {
font-weight: $font-weight-bold;
}
#include nav-icon;
}
.nav-block {
#include typography-nav();
list-style: none;
margin: 0;
padding: 0;
a {
display: block;
border-bottom: 1px solid $color-grey-dark;
padding: $spacing-base 0
}
.active {
font-weight: $font-weight-bold;
}
#include nav-icon;
}
My educated guess that it has to be with an issue regarding display tag but can't seem to find where the issue lays. This is how it looks in chrome which is the desire state. Here is a JS fiddle with the base html template and some of the styles. Because of the size of the project it is very difficult to upload all the styles.
https://jsfiddle.net/ky950382/2/

Cannot reach html templateUrl in Angular 1.6

I'm creating a simple web application in angular 1.6
I create a state for the url "/" but it seems that angular cannot reach the file don´t know why.
Folder structure is this:
So the html load the app like this:
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>paykey</title>
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- -->
<link rel="stylesheet" href="styles/main.css">
</head>
<body ng-app="myApp" >
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
<div ui-view></div>
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/services/codigo.service.js"></script>
</body>
</html>
And the app.js file that has the state is this one:
'use strict';
angular
.module('myApp', [
'ui.router',
'$stateProvider',
'$urlRouterProvider'
])
.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
// .state('home')
.state('main', {
url: '/',
templateUrl: 'views/quote-comps.html',
controller: 'MainT',
controllerAs: 'main'
});
});
So debugging it seems that it passes through stateProvider line but the html does not show up. The only thing I see is the background blonde in css, no errors in console.
The quote-comps.html file is this:
<div ng-controller="MainT" ng-init="init()" style="padding-top: 90px;
padding-left: 20px;">
<div class="bar bar-header disable-user-behavior" >
<div class="header">
<div class="row header-wrapper">
<div class="header-content col text" ng-class="currentPage.title!=undefined ? 'text':''">
<div ng-if="currentPage.title != undefined">
</div>
<img src="images/ICONOS/Logo_banorte_ICO/Logo_Banortexxxhdpi.png" class="bem_image">
<h5 style="text-align: center; color: white; margin-bottom: 0px;margin-top: 0px; font-size: 12px;">Bienvenido</h5>
</div>
</div>
<div class="header-bar" ng-if="currentPage.name.indexOf('login') < 0 && currentPage.name.indexOf('activaToken') < 0 && currentPage.name.indexOf('resynchronize-token') < 0">
<div class="clear"></div>
</div>
</div>
</div>
<div style=" margin-top: 52px;
background-color: #35282B;
height: 450px;
overflow: scroll;">
<h5 style="text-align: center; color: white; font-size: 16px"><!--{{operacion.nombreBeneficario}}-->55 1007 0744</h5>
<h5 style="text-align: center; color: white; ">Has recibido un pago Banorte Móvil por:</h5>
<h3 style="text-align: center; color: white; ">$ {{operacion.importeOperacion}} {{operacion.divisa}}</h3>
<p ng-show="finish" style="text-align: center; font-style: bold; color: white;" ><span>¿Qué deseas hacer?</span></p>
<img ng-show="finish2" class="amount-header ss2" src="../images/ICONOS/Exito_ICO/Exitohdpi.png" >
<p ng-show="finish2" class="amount-header textBox4">¡El deposito fue exitoso!
</p>
<div ng-show="finish" class="comparison-box" ng-class="{'comparison-box-open' : arrowUp}">
<div class="comparison-header-container" ng-click="openMore('first')">
<span> <img style="width: 30px; display:inline;" src="../images/ICONOS/Depositarlo_ICO/Depositarlo.svg"> </img></span>
<span class="comparison-header comboBox">Depositarlo</span>
<img class="arrow" src="images/down_arrow.svg" ng-class="{'rotate180' : arrowUp, 'rotate360' : !arrowUp}">
<!-- <img style="float: right; padding-right: 10px; width: 30px; margin-top: 4px; display: none;" src="images/up_arrow.svg"> -->
</div>
<div class="amounts-container">
<div>
<p style="display: inline;" class="amount-header textBox" ng-class="{'show' : arrowUp && container, 'hide' : !arrowUp}">Ingresa:</p>
<input style="display: inline; text-align: center" class="amount-header inputIngresa" ng-class="{'show' : arrowUp && container, 'hide' : !arrowUp}" placeholder="Cuenta banorte, tarjeta o CLABE">
</div>
<span class="comboBox2"></span>
</div>
<div class="amounts-container">
<div>
<p style="display: inline;" class="amount-header textBox" ng-class="{'show' : arrowUp && container, 'hide' : !arrowUp}">Banco:</p>
<input style="display: inline; text-align: center" class="amount-header inputIngresa" ng-class="{'show' : arrowUp && container, 'hide' : !arrowUp}" placeholder="Cuenta banorte, tarjeta o CLABE">
</div>
<span class="comboBox2"></span>
</div>
<div class="wizard-full">
<!--<button class="btn btn-primary btnSeg seg"> Depositar </button> -->
</div>
<button class="btn cus2" type="submit" ng-click="cancel()">Depositar</button>
</div>
<div ng-show="finish" class="comparison-box seg" ng-class="{'comparison-box-open' : arrowUp2}" style="">
<div class="comparison-header-container" ng-click="openMore('second')">
<span> <img style="width: 30px; display:inline;" src="../images/ICONOS/Depositarlo_ICO/Depositarlo.svg"> </img></span>
<span class="comparison-header comboBox">Cobrarlo en un cajero</span>
<img class="arrow" src="images/down_arrow.svg" ng-class="{'rotate180' : arrowUp2, 'rotate360' : !arrowUp2}" ng-click="restauraE()">
<!-- <img style="float: right; padding-right: 10px; width: 30px; margin-top: 4px; display: none;" src="images/up_arrow.svg"> -->
</div>
<div class="amounts-container">
<div>
<p ng-show="mostrarQuieres" class="amount-header textBox" ng-class="{'show' : arrowUp2 && container, 'hide' : !arrowUp2}">¿Quieres generar tu código de referencia para retirar el efectivo en cajero automático?
</p>
<span>
<img ng-show="mostrarAcude" class="amount-header ss1" src="../images/ICONOS/Exito_ICO/Exitohdpi.png" >
</span>
<div ng-show="mostrarAcude" class="amount-header textbox2" ng-class="{'show' : arrowUp2 && container, 'hide' : !arrowUp2}">Acude a cualquier cajero Banorte, selecciona la opcion retiro de efectivo y captura o escanea este código para retirar tu efectivo
</div>
</div>
</div>
<div class="wizard-full">
<!--<button class="btn btn-primary btnSeg2 seg" ng-click="getCode()"> Generar referencia </button> -->
<button class="btn btn-primary mGenT" type="submit" ng-click="generarTrans()">Generar transferencia</button>
</div>
<div ng-show="mostrar">{{codigoBarras}}
<io-barcode code="123" type="CODE128B"></io-barcode>
</div>
</div>
<div ng-show="mostrar" class="wizard-full">
<button class="btn btn-primary mGenT" type="submit" ng-click="generarTrans()"> d </button>
</div>
</div>
<div class="footer">
"2017 Derechos reservados."</div>
</div>
dependencies:
"dependencies": {
"#uirouter/angularjs": "^1.0.11",
"angular": "^1.6.6",
"bootstrap": "^3.3.7",
"jquery": "^3.2.1"
},
From https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
It seems you need to change $state.Provider to something like the following:
$stateProvider
// .state('home')
.state('main', {
url: '/',
views:{
'quoteCompsView':{
templateUrl: 'views/quote-comps.html',
controller: 'MainT',
controllerAs: 'main'
}
}
});
Then in your html add:
<div ui-view="quoteCompsView"></div>
change url:
.state('main', {
url: '/',
views:{
'quoteCompsView':{
templateUrl: '../views/quote-comps.html',// -------- Here
controller: 'MainT',
controllerAs: 'main'
}
}
You are not adding reference in your main index html file .
I dont see any controller reference on html page
I edited the controller...
angular.module('myApp',[])
.controller('MainT', MainT);
to
angular.module('myApp')
.controller('MainT', MainT);
and works... I really don't know why