AngularJS not show values - javascript

I read This article but still have question because I am new in AngularJS. I create Web Application and add AngularJS Core through Nuget Manager.
I try the code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>First Page</title>
<script src="~/Scripts/angular.js"></script>
</head>
<body ng-app>
{{2+2}}
</body>
</html>
So, here I expect my web page shows 4 but it still shows expression.
Please help.

Check if your script is loading for angular.js.
DEMO
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>First Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-app>
{{2+2}}
</body>
</html>

Related

Trying to import static javascript to thymeleaf

I am working on a java spring project and would like to add a static javascript file to an HTML page. here is what I currently have it seems to work for the css but not the js. the basic file structure is
i am trying to get static js from /static/js/pie-chart.js and put it into /templates/show/match.html here is what i currently have for the html.
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<!- css is working -->
<link rel="stylesheet" href="../static/css/main.css" th:href="#{/css/main.css}">
</script>
</head>
<body>
<!-- the script does not seem to be linking to the page -->
<script src="../static/js/pie-chart.js" th:src="#{/js/pie-chart.js}">
<body>
</html>
Well, the static folder can be treat as the root path.So you don't have to add this '../static/' prefix in your href. You can try as following to see if it works.
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<!- Delete the relative path-->
<link rel="stylesheet" href="/css/main.css">
</script>
</head>
<body>
<!- Delete the relative path-->
<script src="/js/pie-chart.js">
<body>
</html>
Use this in order to link your Js file in HTML Page :--
<script src="js/pie-chart.js">
This image in my sample boot project. you can using th:href="#{/your/js}".
like this :
readingList.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Reading List</title>
<link rel="stylesheet" th:href="#{/css/style.css}" />
</head>
<body>
<label>Reading List!!</label>
</body>
</html>

Android TextView with HTML and JavaScript

I have this HTML:
<!DOCTYPE html> <html lang="en" xmlns:m="http://www.w3.org/1998/Math/MathML">
<head>
<meta charset="utf-8">
<script src="file:///android_asset/mathscribe/jquery-1.4.3.min.js"></script>
<script src="file:///android_asset/mathscribe/jqmath-etc-0.4.0.min.js"></script>
<title>Displaying maths</title> </head> <body> $$y-y_0=m(x-x_0)$$ </body> </html>
And I want to display the result in an Android TextView. I tried to use Html.fromHtml() but don't work.
it's: http://mathscribe.com/author/jqmath.html

window.opener not working properly

I'm trying to use a simple scenario in which function from parent window is called from a popup.My source looks like this:
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Parent window</title>
</head>
<body>
<script type="text/javascript">
function twitterAccess() {
console.log('ok!')
}
window.open ("popup.html","mywindow", "width=350,height=250");
</script>
</body>
</html>
popup.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>popup</title>
</head>
<body>
<script type="text/javascript">
window.opener.twitterAccess()
</script>
</body>
</html>
But it allways gives me Uncaught TypeError: Object [object global] has no method 'twitterAccess'. I have also tried using it with window.parent, parent.window, parent.window.opener and a dozen of other suggestions found on the web but it's allways the same. Can you advice me on what am i doing wrong? I'm sure it's something really silly.

Can't call javascript file from my html page

I'm new to JavaScript and just want to put my JavaScript code in another file.
This is my html page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>my badass page</title>
<script type="text/javascript" scr = "testing.js"></script>//this contains the function I want to call
</head>
<body id="body">
<button type="button", onclick="showDate()">show the date</button>
</body>
</html>
This is the testing.js file:
function showDate() {
alert ("this works")
}
I'm assuming that I just make a beginner mistake because it seems really common but I can't figure it out.
you spelled the 'src' attribute incorrectly on your tag
you spelled it scr, it should be src
this:
<script type="text/javascript" scr = "testing.js"></script>
should be this:
<script type="text/javascript" src = "testing.js"></script>
change the button to
<button type="button" onclick="showDate()">show the date</button>
and change scr to src
EDIT: source that works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>my badass page</title>
<script type="text/javascript" src="testing.js">
</script>
</head>
<body id="body">
<button type="button" onclick="showDate();">show the date</button>
</body>
</html>
Quick use of html validator such as http://validator.w3.org/nu/ will uncover lots of problems in your code. Just copy paste and correct the errors.

JavaScript won't work if placed inside the body of a web page?

I'm new to JavaScript and I've learned that JavaScript can be place between the <head></head> or <body></body> sections, I have been working in a project and it works fine inside the head but not the body section of the page.
examples:
working fine like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Page</title>
<script>
function yetAnotherAlert(textToAlert) {
alert(textToAlert);
}
yetAnotherAlert("Hello World");
And is not working this way:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Page</title>
</head>
<body>
<script>
function yetAnotherAlert(textToAlert) {
alert(textToAlert);
}
yetAnotherAlert("Hello World");
</script>
</body>
</html>
Your code snippet didn't show you closing the tag. Double check if you close your script block correctly.
It's also better to specify the type of scripting language too.
<script language='javascript'>
....
</script>

Categories

Resources