0

I am working on a project using both JQuery and Angular2 in order to use a JQuery library.

My problem is when it comes to replace DOM element with Angular2 code using JQuery.

I am expecting the below code to add Angular code in the DOM element:

let myContainer = <HTMLElement>document.querySelector(".question-text");
myContainer.innerHTML = "<span>{{model?.text}}</span>";

What it does instead, is to replace the innerHTML setting the {{model?.text}} as a string and not as a dynamic content.

Is there a way to achieve it? Any help is welcome

1
  • if you want to add dynamic element you can use renderer2 angular service Commented Jul 18, 2018 at 9:23

2 Answers 2

0

Maybe you can find a Solution here: TypeScript - Append HTML to container element in Angular 2

I would suggest to use ngIf and set a flag if you want to render your content, so you actually need no jQuery for it.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for the effort, I tried your solutions but unfortunately the result is the same - it parses the {{model?.text}} as a string and not as a dynamic content. The *ngIf approach looks more suitable though. Thank you
0

You need to something like $compile( "<span>{{model?.text}}</span>" )( $scope ); Inject $compile before that

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.