I want to render a HTML file into a component. This HTML has some libraries connected to it which show certain content. How can this be done? I tried DomSanitizer but it doesn't work.
Read the file using typescript/javascript.
Depending on your HTML, you can use [innerHtml] attribute. See
Code:
<div [innerHtml]="yourHTML"></div>
Note: Be aware of XSS vulnerability.
Related
I am developing a web application using Microsoft .NET MVC. As the default CSHTML views are not always responsive enough, there are some pages implemented in Angular. The rendered CSHTML page pretty much only includes a directive to invoke an Angular component, and Angular takes care of the rest.
Now, one of the Angular pages looks like its HTML template is going to get quite long. We're talking about almost a thousand lines of HTML code here. That's just the HTML template, not the Angular component handling it.
So I thought it would be better for development and maintenance to split the template into several HTML files, where the main HTML file would include other HTML files. But this doesn't seem to be possible.
Googling for "include HTML file in another in Angular" returned results about using the <ng-include> directive, but unfortunately that seems to only have been supported in the original AngularJS, not in the new Angular. At least the examples I used didn't work.
Is this somehow possible in Angular, or do I have to actually make the included HTML files into separate components?
const template = `
<div> Your template here! </div>
`;
export default template;
import html from 'template.html'
Then
declare module '*.html' {
const value: string;
export default value
}
And
<div [innerHTML]="theHtmlString"></div>
I'm trying to use an HTML template as a frame, and want to load the content inside of it depending on the route.
I'm used to PHP, so I know the require($file) option embeded in the code so it will render the needed file inside of the template, so I'd like to know if there is any thing similar to it.
I've tried to search about it, but it isn't that clear. So I've thought in two options, the first one is to split the template in two parts, and put the file content in between these two when sending the response.
This is what I am aiming for in the main HTML file and be able to render it in the NodeJS response.
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>My App</h1>
{ require($file); }
</body>
</html>
Easy way is to read the template (with some placeholders for the variable text) into a variable. Then read the text that you want to put into the placeholders into another variable. Then just replace the placeholders. Output the final string.
You can use https://www.npmjs.com/package/mustache to render templates in node - it includes partial HTML templates and should feel familiar to your PHP experience.
(Just to answer you question directly - no, HTML by itself is static, and with exception of iframe, there is no safe way to include partial HTML within another HTML page.)
you can use the iframe HTML object to embed it inside your file
<iframe src="<source html file location>"></iframe>
No. There's no way to add a 'variable' in HTML since HTMl it static. You need a dynamic language for that such as:
mustache.js
handlebars.js
pug/jade
Or if you're feeling really passionate about web development, and you are willing to begin hating html, then you should defiantly check out:
react.js Personal Favorite
angular
Let me know if you have any questions!!
I want user to be able to easily upload screenshots into my application. (preferably without to many js/ajax trickery)
Is there a standard way in Wicket to allow an image to be pasted in some FormComponent (textarea? div with contenteditable?) and used as a regular input, so that when the form is posted, I get a byte[]/stream in the Java code?
You have to use <input type="file"> in the markup and FileUpload component at the Java/server code.
If you need fancier ways than Upload button than you will need to use some Javascript library.
Here is the plain Wicket example
If you use Bootstrap then you may use Wicket-Bootstrap integrations like FileInput or DropZone
so I am using the standard template from AngularDart that comes from stagehand web-angular-simple.
Now, if I have something hardcoded in index.html and try to manipulate it from main.dart using querySelector, everything works fine.
But how can I use querySelector to manipulate the AppComponent that was loaded into the index.html file in the template?
So basically my question is: how to manipulate dynamically loaded elements in dart.
(p.s. I just started out in AngularDart...)
thanks in advance
You can inject ElementRef and through it access nativeElement - this will be the DOM node of you component.
The question is why do you need? Almost always there is a way to do what you need through interacting with angular templates.
Let's say I have an angular directive for displaying media files (images & videos). It could look like this:
<div my-media mediatype="MediaFile.Type" mediapath="MediaFile.Path"></div>
Is it possible to hide that directive's attribute in html output? Or at least it's value.
For example, I have a similiar directive which is repeated with ng-repeat and it's "mediapath" is base64 code from html input files. Those paths greatly increase size of html and it is very hard to modify that kind of code. Also browser always freezes when inspecting such an element.
You can call to a $scope function that returns the value.