I am creating a simple static website using AngularJS.
I am routing ng-view on my template to different html pages, like this one:
home.html:
<script type="text/ng-template" id="views/home.html">
You are in home
</script>
Here is my Index.html:
<!DOCTYPE html>
<html lang="en" ng-app="myApp" >
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<title>My Website</title>
<base href="/">
<meta name="author" content="Me">
</head>
<body ng-controller="ContentController">
<h1>My Website</h1>
<ul class="main-nav" id="main-nav">
<li><a href="home"><i class="fa fa-home"></i>Home</li>
<li><a href="portfolio"><i class="fa fa-comment"></i>Portfolio</li>
<li><a href="articles"><i class="fa fa-comment"></i>Articles</li>
<li><a href="books"><i class="fa fa-comment"></i>Books</li>
<li><a href="about"><i class="fa fa-shield"></i>About Me</li>
</ul>
<ng-view></ng-view>
</body>
</html>
My routing works just after the second time I click on each one of the links (portfolio, articles, ...).
The first time I click on a link, the controller is executed, but the view does not show me the html content (i.e. "You are in home" does not appear on my initial click, just after the second one).
If I write the content of home.html on the index.html file, then it works correctly also on my initial click.
However, I would like to understand why it is not loading correctly on the first time I click on each one of these links.
Could you guys help me?
Is there a proper way to use ng-template on a separate file? Or should I use a work around in order to reload my ng-template after the first click?
Thank you
If I remove the ng-template, the issue is solved.
I will study more to understand how to use ng-template on separate files and will write it here.
Related
I am trying to display content using javascript DOM but every time I run my solution I get a blank page. My HTML file is as follows:
<!DOCTYPE html>
<html>
<head>
<title>Radiant HQ</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<nav id="navigationcontent"></nav>
<script type="text/javascript" src="assets/js/radiant.js">
</script>
</body>
</html>
My js file looks this way:
#import ('../css/style.css');
document.getElementById("navigationcontent").innerHTML=`
<ul>
<li>Home </li>
<li>About Us </li>
<li>Research </li>
<li>Contacts </li>
</ul>`;
Your code works. There is one problem though.
It's getting stuck on the #import ('../css/style.css'); line. Try removing that whole line and include your CSS some other way. Typically this in done in the head of the document via html.
I try to use prismjs http://prismjs.com/download.html for code highlighting, but it is not working see this fiddle http://jsfiddle.net/939u16ac/ I am getting the rendered HTML instead of the markup PFA markup and Screenshot
HTML File:
<!doctype html>
<html lang="en">
<head>
<title> Demo</title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="lib/prism.css">
<script src="lib/prism.js"></script>
</head>
<body onload="">
<pre class="line-numbers language-markup">
<code class="">
<ol type="1">
<li>
href atribute is must and id, class, title attribute are optional
</li>
<li>
In angular application or you are not having any navigation link, use <b>javascript:void(0)</b> in href attribute value
</li>
</ol>
<a id="optionalID" class="optionalClass" title="optionalTitle" href="Product.html" >Product Page</a>
</code>
</pre>
</body>
</html>
Could any one spot me where i went wrong in implementing it?
Thanks in advance for any help.
I have created a very simple test page below. When I open it in Internet Explorer and start tabbing through it then it tabs through all the links for the first time. However it doesn't tab through them for the second time. It just cycles through address bar, home button and current tab. It never goes to the links. It is happening because of including the javascript file snare.js but we need it on our page. Can anyone suggest any way to overcome it? I have tried several approaches but it doesn't work (copying file locally, trying to focus on links etc.).
Note - The problem is only happening in Internet Explorer.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Test Title</TITLE>
<script type='text/javascript' language='JavaScript' src='https://mpsnare.iesnare.com/snare.js'> </script>
</HEAD>
<BODY>
Test
Test2
Test3
</BODY>
</HTML>
Your javascript error i try remove script tag it woking.
hope this help!
You can trick javascript focus on link3 when blur link1 or use other trick my code i test working ok
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Send Money - Set Up Payment - U.S. Bank</TITLE>
<script type='text/javascript' language='JavaScript' src='https://mpsnare.iesnare.com/snare.js'> </script>
</HEAD>
<BODY>
<div>
<a id="link1" onBlur="this.tabIndex=1" href="http://www.google.com">Test</a>
<a id="link2" onBlur="this.tabIndex=2" href="http://www.google.com" >Test2</a>
<a id="link3" onBlur="document.getElementById('link1').focus()" href="http://www.google.com">Test3</a>
</div>
</BODY>
</HTML>
I've recently been trying to use or familiarize myself with the JQuery tabs function. However everytime I've tried using it I get the error "undefined is not a function". I've researched this problem and a lot say it may have to do with the .js file not being loaded but that is not the case as my console tab shows it being loaded.
Here is the HTML file I have been trying to test out:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="Portal.css" media="screen" />
<script type="text/javascript" src="Portal.js"></script>
<script src="tabs.js"></script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href='#tab1'>Tab 1</a></li>
<li><a href='#tab2'>Tab 2</a></li>
<li><a href='#tab3'>Tab 3</a></li>
</ul>
<div id='tab1'>
<p>Hi, this is the first tab.</p>
</div>
<div id='tab2'>
<p>This is the 2nd tab.</p>
</div>
<div id='tab3'>
<p>And this is the 3rd tab.</p>
</div>
</div>
</body>
</html>
And the tabs.js file (which throws the undefined error when debugging):
$(document).ready(function () {
$("div.tabs").tabs();
});
Thanks. I can provide more details if needed. No CSS is being used yet (but I don't believe that to be the issue here).
Make really sure, that you are loading the js from the external sources.
I had a similar problem. My code was working in konqueror, opera and some firefox / iceweasel browsers, but not in others and not in chromium.
It turned out, that while my page was https hosted, i tried to load the external js over insecure http connection. These links were silently discarded by the "not working" browsers... i spent hours on that frack.
Hope this helps you or others.
You're selecting class tabs but what you have is ID tabs.
Change it to:
$( 'div#tabs' ).tabs();
Or change your HTML to:
class="tabs"
$( "#tabs" ).tabs() use this instead of $("div.tabs").tabs()
I am new to jquery and can't even assume how deeply this issue can go.
When the external page (in this case shop.php) is loaded into index.php, by Jquery function .load(); , it falls apart. Many jquery commands and plugins, that are applied to the shop.php page, aren't working.
This confuses me, because some of js commands and plugins still works. Obviously i can't say that files are not loaded completely, just majority of them are not working.
When I paste shop.php content into index.php, it works perfect. Also when i add desired js code into shop.php (wrapped into script tag), it works as well.
I really don't expect from anyone to look deeply into this problem. I just wanna know if this is common issue, and is there simple explanation for it ?
If not i'll seek for some different approach.
My code:
index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.10.4.min.css">
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.4.min.js"></script>
<script type="text/javascript" src="js/shop.js"></script>
<script type="text/javascript" src="js/jquery.touchcarousel-1.2.js"></script>
<script type="text/javascript" src="js/jquery.themepunch.revolution.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/jquery.ddslick.js"></script>
<script type="text/javascript" src="js/top-navigation.js"></script>
</head>
<body>
<div id="top-bar"><?php include("top-bar.php"); ?></div>
<div id="pageWraper"><?php include("home.php"); ?></div>
</body>
</html>
top-bar.php
<div id="nav">
<ul id="navigationWraper">
<li>Home</li>
<li>About Us</li>
<li>Services</li>
<ul class="submenu">
<li>asdasd</li>
<li>asdasdas</li>
<li>derwer</li>
</ul>
<li>Shop</li>
<li>Portfolio</li>
<li>Gallery</li>
<li>Contact Us</li>
</ul>
</div>
shop.php
<div id="shop">
<div id="shopheader">
<div id="shopitemstop">
<div id="productcat">
<!-- bunch of code -->
</div>
</div>
</div>
</div>
Jquery:
$(document).ready(function(){
$(function() {
$("a.menuLink").on("click", function(e) {
e.preventDefault();
$("#pageWraper").load(this.href);
});
});
});
Hope this helps
Thanks,
Update :
I added:
<script type="text/javascript">
$(document).ready(function(){
$.getScript("js/shop.js");
$.getScript("js/jquery.touchcarousel-1.2.js");
$.getScript("js/main.js");
});
</script>
on top of shop.php page, dont know how right this is, but its working now.
Only thing that bugs me is if i remove jquery.touchcarousel-1.2.js from index.php head, page falls apart. It is like, only working if both of them are loaded ????
Question:
I really don't expect from anyone to look deeply into this problem. I
just wanna know if this is common issue, and is there simple
explanation for it ?
Answer:
Yes, it is a common problem for Ajax/dynamically loaded content.
The cause is: that most plugins work on the DOM as it exists when the plugin is run (unless they were specifically created to work with dynamic content).
The fixes include:
Find another plugin that is tolerant of dynamic content
Re-run the plugins
Strip out existing plugins and re-run the plugins (takes some effort to figure out some plugins)
Don't load content dynamically for plugins that do not support it