How to display only href HTML code in Angular? - angularjs

I use {{message}} in template HTML.
This code shows HTML as text in page.
How I can show only one HTML tag <a href> as HTML in page?

if have included ng-sanitize (doc) as dependency you could its directive "ng-bind-html" to sanitize your HTML-strings
<div ng-bind-html="message">

Related

Use of ngsanitize with css

While using ngsanitize. It displays only html without css applied.
For example:
The above image should be the output but using ngsanitize ,it displays only the text
What could be added with ngsanitize to display elements with proper css.
<p ng-bind-html ="the text to be displayed(test video)"></p>
if i understood your question correctly, fiddle
you can use $sce.trustAsHtml(), to use inline style directly into the html string, you could do it like this, controller:
$scope.trustAsHtml = function(string) {
return $sce.trustAsHtml(string);
};
And in HTML
<div data-ng-bind-html="trustAsHtml(htmlString)"></div>
Please try with $sce. Before binding it to the scope variable that you use for ng-bind-html. An example below
<p ng-bind-html ="styledHTML"></p>
And in your controller
$scope.styledHTML = $sce.trustAsHtml('<span style="background-color: cyan;">test video</span>');

how to evaluate script tag with some javascript in json responce in angular

I am using AngularJS v1.4.8
when i try to display that field with ng-bing-html, whole page content overwrite.
for example
<script>
document.write("hello");
</script>
url start infinite loading instead of ng-bind-html tag.
The write() method writes HTML expressions or JavaScript code to a document and it will delete all existing HTML.
The ng-bind-html directive is a secure way of binding content to an HTML element.
Refer to the ng-bind-html in following document.
https://docs.angularjs.org/api/ng/directive/ngBindHtml
<div ng-controller="ExampleController">
<p ng-bind-html="myHTML"></p>
</div>
$scope.myHTML =
'I am an <code>HTML</code>string with ' +
'links! and other <em>stuff</em>';

Ionic2 components no style after innerHTML

Here's what i'm trying to do:
I have a string with html and ionic elements in my .ts file:
page_content = "<ion-card class='card-ios'><ion-card-header>Header</ion-card-header><ion-card-content>Card Content</ion-card-content></ion-card>"
then i want to inject that string in a div in the html page:
<ion-content padding class="home">
<div [innerHTML]="sanitizer.bypassSecurityTrustHtml(page_content)">
</div>
</ion-content>
the problem is that the style of the card is not applied to the content, if i insert the code directly in the html it shows fine.
with innerHTML
inserted directly
Thanks in advance.

How to make a button in ng-repeat open a full url link in ionic and angularfire?

Assuming i am using this in my controller
var messagesRef = firebase.database().ref().child("messages");
$scope.messages = $firebaseArray(messagesRef);
And in my html is
<li ng-repeat="message in messages">
<p>{{ message.user }}</p>
<p>{{ message.text }}</p>
<button href="{{ message.weblink }}">OPEN THIS LINK</button>
That {{website.weblink}} for example is www.google.com from my firebase database.
How can i make that button work to open www.google.com using that button because it is not working .
To summarize, <a ng-href=""> should be used instead of <button href="">.
Using Angular markup like {{hash}} in an href attribute will make the
link go to the wrong URL if the user clicks it before Angular has a
chance to replace the {{hash}} markup with its value. Until Angular
replaces the markup the link will be broken and will most likely
return a 404 error. The ngHref directive solves this problem. - ngHref

How to cut HTML tags inside ng-bind-html?

I use ng-bind-html in template HTML:
<div ng-bind-html="message.message + getTemplate(message.file)"></div>
Can I cut HTML and others tags only for this part message.message inside ng-bind-html?

Resources