I would just like to know how to display AngularJS in Angular 2+ (I have a very unique situation that requires this)
So far this is what I have tried:
https://stackblitz.com/edit/angular-wbbzbz?file=src/app/app.component.ts
To give you an idea of what is happening on stackblitz:
I have a basic html string (which I got from here: https://www.w3schools.com/angular/tryit.asp?filename=try_ng_default):
myHtml = `
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="">
<p>Input something in the input box:</p>
<p>Name : <input type="text" ng-model="name" placeholder="Enter name here"></p>
<h1>Hello {{name}}</h1>
</div>
</body>
</html>
`;
And through a pipe, I display it using:
<div [innerHTML]="myHtml | pipeSanitizeHtml"></div>
But I end up having this (broken AngularJS):
AngularJS will work if you put this in your Angular 2+ index.html's header:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
Related
I'm trying to create an area in which you can enter text into a text box and display the written text onto a box above in HTML. I'm very new to HTML so any help will be greatly appreciated. I drew a beautiful picture of what I'm trying to make.
The best way to deal with this situation is use Javascript or jQuery which is javascript's library itself. Let me show you how you should do it in jQuery
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$("#form-to-be-submitted").click(function(){
$(".whatever-styling-you-want").html($("#textBox").val());
});
});
</script>
<div class="whatever-styling-you-want">
</div>
<!-- Your text box and submit button -->
<div>
<input type="text" id="textBox" placeholder="Please input your text here..."/>
<input id="form-to-be-submitted" value="submit" type="button"/>
</div>
Javascript's way is also the same. No need to use the click function but use javascript's on function with the 'click' event.
I hope this helps.
<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
</head>
<body>
<p id="x"></p><br>
<input id="value"><input type="button" value="submit" onClick="getV()">
<script>
function getV(){document.getElementById("x").innerHTML = document.getElementById("value").value;}
</script>
</html>
I want to get the data from the another html file using angularjs $http get method, but i did't get anything
below is my code
<!DOCTYPE html>
<html>
<head ng-app="myApp">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
<p>{{welcome}}</p><br />
<h1>{{error}}</h1>
</div>
<script>
var app=angular.module('myApp',[])
app.controller('myCtrl',['$scope','$http',function($scope,$http){
$http.get('home.html').than(function(response){
$scope.welcome=response.data;
},function(reason){
$scope.error=reason.data;
});
}]);
</script>
</body>
</html>
Below is my another html file code
<p>This is home page</p>
it should be then not than
.then(function(response){
Demo
I am trying to load templates from a file into an HTML file using a script tag. I want to use this as a template in UnderscoreJS - but I'm not able to load the file:
//main.js
this.template = _.template($("#add-question").html());
console.log("testing");
console.log(this.template({
question: "How are you doing?",
yesOrNo: true
}))
//console output:
testing Main.ts:37
Main.ts:38
//main html file:
<html xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<script type="text/template" id="add-question" src="client/add-new-question.html"></script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js" type="text/javascript"></script>
<script src="https://rawgithub.com/jashkenas/underscore/master/underscore-min.js"></script>
<script data-main="main.js" src="build/require.js"></script>
</body>
</html>
// client/add-new-question.html
<form id="testForm">
<span>"<% question %></span>
<input id="questionInput" type="text">
<span>"<% yesOrNo %></span>
<input id="typeInput" type="checkbox">
</form>
Update:
Here's the updated HTML in in which I've tried loading the html though a script tag in the body. Still doesn't work. This is how its expected to be done when rendering the template with UnderscoreJS. I want to be able to load the template with requireJS but render it using the underscoreJS template function.
<body>
<script type="text/template" id="add-question">
<form id="testForm">
<span>"<%= question %></span>
<input id="questionInput" type="text">
<span>"<%= yesOrNo %></span>
<input id="typeInput" type="checkbox">
</form>
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="https://rawgithub.com/jashkenas/underscore/master/underscore-min.js"></script>
<script data-main="main.js" src="build/require.js"></script>
</body>
You have to use <%= to output variables instead of <%.
It looks like you are using requirejs.
So you could also use the tpl extension and store your underscore template in .tpl files:
https://github.com/ZeeAgency/requirejs-tpl
define(['tpl!client/add-new-question.html'], function(tpl) {
console.log(tpl({
question: "How are you doing?",
yesOrNo: true
}));
});
Links:
How to use underscore.js as a template engine?
and underscore.js
The following code displays only the input box when run in the browser (Chrome). It seems to have broken when I attempted using the ng-controller directive.
<!doctype html>
<html ng-app="">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"> </script>
<script>
function SController($Scope) {
$Scope.customers =
[{name:'John Smith',city:'Kingston'},
{name:'Jane Doe',city:'Ocho Rios'},
{name:'Brian Wade',city:'Negril'},
{name:'John Barker',city:'Mandeville'} ];
}
</script>
</head>
<body ng-controller="SController">
<div class="container">
<input type="text" data-ng-model="name"/>
<ul>
<li ng-repeat="person in customers | filter:name | orderBy:'city'">{{ person.name}} - {{ person.city }} </li>
</ul>
</div>
</body>
</html>
Well, at first sight, it seems that you're using $Scope instead of the correct $scope. Replace those occurrences and try again.
<!DOCTYPE html>
<html>
<head>
<script>
function getElements()
{
var x=document.getElementsByName("first");
alert(x.length);
}
</script>
</head>
<body>
<h1 name="first">hi</h1>
<form>
uname:<input type="text" name="first" value="sree"> <br>
password:<input type="password" name="first" value="dhar">
<p name="first">hello</p>
<input type="button" onclick="getElements()" value="How many elements named 'x'?">
</form>
</body>
</html>
I have this code.The alert is showing 4 in chrome.But in ie it is showing 2.What might be the reason.
Thanks in advance...
The name attribute is not actually a valid attribute for h1 or p elements.
It is however, valid for the two input elements, so that is probably why it is returning 2.
IE8 only recognizes the name attribute on the <input>s. Use a class instead.Fiddle of your code: http://jsfiddle.net/ChpCr/Fiddle: http://jsfiddle.net/ChpCr/1/