Trouble sanitizing HTML in angular 6/ionic












0















I would like to sanitize the HTML tags out of text coming in from the server on my ionic/angular 6 app. The object looks like this



{note: '<p>lorem ipsum</p>'}


The error I'm currently getting is urlSan is not defined, but on top of that, I am not super sure I am using this feature correctly. I used a version of this walkthrough



This is the page.ts



import { Component, OnInit, Input } from '@angular/core';
import { LoadingService } from '../loading.service';
import { FinaeoApiService } from '../finaeo-api.service';
import { ActivatedRoute } from '@angular/router';
import * as _ from 'lodash';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
selector: 'app-contact-individual',
templateUrl: './contact-individual.page.html',
styleUrls: ['./contact-individual.page.scss'],
})
export class ContactIndividualPage implements OnInit {
contact: any;
initials: string = '';
safeHTML: SafeResourceUrl;

private htmlValue: string;

constructor(
private loadingService: LoadingService,
private api: FinaeoApiService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer
) { }

urlSan(value: string) {
this.htmlValue = value;
this.safeHTML = this.sanitizer.bypassSecurityTrustResourceUrl(value);
};

async ngOnInit() {
await this.loadingService.load(async () => {
const routeParams = <any> this.route.params;
this.contact = await this.api.getModel('Contact', routeParams._value.id);
_.forEach(this.contact.notes, function(html) {
urlSan(html.note)
})
this.initials = this.contact.firstName != null ? this.contact.firstName.charAt(0) + this.contact.lastName.charAt(0) : '';
});
}


}









share|improve this question























  • Shouldn't you use this.urlSan?

    – Phix
    Nov 13 '18 at 19:29











  • why your not using bypassSecurityTrustHtml insted of bypassSecurityTrustResourceUrl that your using? you said you want HTML not url... Also you need to use this.urlSan()

    – Talg123
    Nov 13 '18 at 19:31


















0















I would like to sanitize the HTML tags out of text coming in from the server on my ionic/angular 6 app. The object looks like this



{note: '<p>lorem ipsum</p>'}


The error I'm currently getting is urlSan is not defined, but on top of that, I am not super sure I am using this feature correctly. I used a version of this walkthrough



This is the page.ts



import { Component, OnInit, Input } from '@angular/core';
import { LoadingService } from '../loading.service';
import { FinaeoApiService } from '../finaeo-api.service';
import { ActivatedRoute } from '@angular/router';
import * as _ from 'lodash';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
selector: 'app-contact-individual',
templateUrl: './contact-individual.page.html',
styleUrls: ['./contact-individual.page.scss'],
})
export class ContactIndividualPage implements OnInit {
contact: any;
initials: string = '';
safeHTML: SafeResourceUrl;

private htmlValue: string;

constructor(
private loadingService: LoadingService,
private api: FinaeoApiService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer
) { }

urlSan(value: string) {
this.htmlValue = value;
this.safeHTML = this.sanitizer.bypassSecurityTrustResourceUrl(value);
};

async ngOnInit() {
await this.loadingService.load(async () => {
const routeParams = <any> this.route.params;
this.contact = await this.api.getModel('Contact', routeParams._value.id);
_.forEach(this.contact.notes, function(html) {
urlSan(html.note)
})
this.initials = this.contact.firstName != null ? this.contact.firstName.charAt(0) + this.contact.lastName.charAt(0) : '';
});
}


}









share|improve this question























  • Shouldn't you use this.urlSan?

    – Phix
    Nov 13 '18 at 19:29











  • why your not using bypassSecurityTrustHtml insted of bypassSecurityTrustResourceUrl that your using? you said you want HTML not url... Also you need to use this.urlSan()

    – Talg123
    Nov 13 '18 at 19:31
















0












0








0








I would like to sanitize the HTML tags out of text coming in from the server on my ionic/angular 6 app. The object looks like this



{note: '<p>lorem ipsum</p>'}


The error I'm currently getting is urlSan is not defined, but on top of that, I am not super sure I am using this feature correctly. I used a version of this walkthrough



This is the page.ts



import { Component, OnInit, Input } from '@angular/core';
import { LoadingService } from '../loading.service';
import { FinaeoApiService } from '../finaeo-api.service';
import { ActivatedRoute } from '@angular/router';
import * as _ from 'lodash';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
selector: 'app-contact-individual',
templateUrl: './contact-individual.page.html',
styleUrls: ['./contact-individual.page.scss'],
})
export class ContactIndividualPage implements OnInit {
contact: any;
initials: string = '';
safeHTML: SafeResourceUrl;

private htmlValue: string;

constructor(
private loadingService: LoadingService,
private api: FinaeoApiService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer
) { }

urlSan(value: string) {
this.htmlValue = value;
this.safeHTML = this.sanitizer.bypassSecurityTrustResourceUrl(value);
};

async ngOnInit() {
await this.loadingService.load(async () => {
const routeParams = <any> this.route.params;
this.contact = await this.api.getModel('Contact', routeParams._value.id);
_.forEach(this.contact.notes, function(html) {
urlSan(html.note)
})
this.initials = this.contact.firstName != null ? this.contact.firstName.charAt(0) + this.contact.lastName.charAt(0) : '';
});
}


}









share|improve this question














I would like to sanitize the HTML tags out of text coming in from the server on my ionic/angular 6 app. The object looks like this



{note: '<p>lorem ipsum</p>'}


The error I'm currently getting is urlSan is not defined, but on top of that, I am not super sure I am using this feature correctly. I used a version of this walkthrough



This is the page.ts



import { Component, OnInit, Input } from '@angular/core';
import { LoadingService } from '../loading.service';
import { FinaeoApiService } from '../finaeo-api.service';
import { ActivatedRoute } from '@angular/router';
import * as _ from 'lodash';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

@Component({
selector: 'app-contact-individual',
templateUrl: './contact-individual.page.html',
styleUrls: ['./contact-individual.page.scss'],
})
export class ContactIndividualPage implements OnInit {
contact: any;
initials: string = '';
safeHTML: SafeResourceUrl;

private htmlValue: string;

constructor(
private loadingService: LoadingService,
private api: FinaeoApiService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer
) { }

urlSan(value: string) {
this.htmlValue = value;
this.safeHTML = this.sanitizer.bypassSecurityTrustResourceUrl(value);
};

async ngOnInit() {
await this.loadingService.load(async () => {
const routeParams = <any> this.route.params;
this.contact = await this.api.getModel('Contact', routeParams._value.id);
_.forEach(this.contact.notes, function(html) {
urlSan(html.note)
})
this.initials = this.contact.firstName != null ? this.contact.firstName.charAt(0) + this.contact.lastName.charAt(0) : '';
});
}


}






angular typescript ionic-framework






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 19:27









IWIIWI

377624




377624













  • Shouldn't you use this.urlSan?

    – Phix
    Nov 13 '18 at 19:29











  • why your not using bypassSecurityTrustHtml insted of bypassSecurityTrustResourceUrl that your using? you said you want HTML not url... Also you need to use this.urlSan()

    – Talg123
    Nov 13 '18 at 19:31





















  • Shouldn't you use this.urlSan?

    – Phix
    Nov 13 '18 at 19:29











  • why your not using bypassSecurityTrustHtml insted of bypassSecurityTrustResourceUrl that your using? you said you want HTML not url... Also you need to use this.urlSan()

    – Talg123
    Nov 13 '18 at 19:31



















Shouldn't you use this.urlSan?

– Phix
Nov 13 '18 at 19:29





Shouldn't you use this.urlSan?

– Phix
Nov 13 '18 at 19:29













why your not using bypassSecurityTrustHtml insted of bypassSecurityTrustResourceUrl that your using? you said you want HTML not url... Also you need to use this.urlSan()

– Talg123
Nov 13 '18 at 19:31







why your not using bypassSecurityTrustHtml insted of bypassSecurityTrustResourceUrl that your using? you said you want HTML not url... Also you need to use this.urlSan()

– Talg123
Nov 13 '18 at 19:31














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288202%2ftrouble-sanitizing-html-in-angular-6-ionic%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288202%2ftrouble-sanitizing-html-in-angular-6-ionic%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong