I'd like to show code snippets within my angular2 application. But I am not able to paste simple javascript code within a code-tag.
I always need to add a second curly bracket and I have to add ngNonBindable. But I don't want to add a second bracket.
Has anyone a solution to this?
http://plnkr.co/edit/OzlHLJxgwSvUffryV3e4
this is my app.component.html:
<h1>Here is the documentation for the model:</h1>
<pre>
<code ngNonBindable>
export model = new Model({
a:1,
b:function(){}
})
</code>
</pre>
The User should see:
here is the documentation for the model:
export model = new Model({
a:1,
b:function(){}
})`
Using pre & code tag The <code> tag is used to define a piece of computer code. The content inside is displayed in the browser's default monospace font. So, by using <pre> & <code>, you can display a code snippet such as function.
We are glad to introduce Angular Snippets, a utility for adding Syncfusion Angular components in the HTML file of an Angular application. This utility is available in our 2021 Volume 3 release. This code snippet utility saves significant time for developers in adding Syncfusion Angular components to their projects.
An Angular HTML template renders a view, or user interface, in the browser, just like regular HTML, but with a lot more functionality. When you generate an Angular application with the Angular CLI, the app. component. html file is the default template containing placeholder HTML.
I think the simplest way is to use [innerHTML]="xxx"
and hold the code in the components class
<pre>
<code [innerHTML]="code"></code>
</pre>
export class AppComponent {
code = `
export model = new Model({
a:1,
b:function(){}
})
`
}
Plunker example
In RC.1 some styles can't be added using binding syntax might also be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With