How can I replace the variable when binding in angular7
Suppose I have string "WelCome to my site"
When binding it should display
WelCome Mike to my site
You should to use variable in your html template, like {{welcomeMsg}}, and build this string in .ts component (if you are using typescript).
welcomeMsg = "Welcome to my site"; // default value
And When application will know usernmae or whatever you need, just change this value as you wish:
...
welcomeMsg = "Welcome " + username + " to my Site.";
...
Html template will be updated with the new value.
Or the second opportunity is to use more flexible variable like:
<div>
Welcome {{usename}} to my Site!
</div>
When the username variable will be filled with some of the value it will be automatically added to the welcome message.
if apart from the name the text remain same and to bind in html then the preferable way in html :-
<div>
Welcome {{_userName}} to my Site!
</div>
In HTML file you can write as follows:
<div>
<h1>
WelCome {{username}} to my site!
</h1>
</div>
and if you are using ts file (TypeScript) you can initialize the username over there.
export class AppComponent {
username= 'Mike';
}
hope this helps you.
Related
I am trying to include HTML tags in groovy code, My requirement is to add something like -- thanks and regards (in one line), in next line a image, followed by name (in new line), kindly let me know how I can achieve this.
I have tried below and it didn't worked.
body: """
Approval is required. Please provide acceptance \n
Visit the below link to approval/decline \n\n
Note This is system generated email
""" + ''' </p><p Regards,</p>src="<image path>" alt="yes"><br><br><b><span
Cloud></b></span><br>myname<br></p>''', mimeType: 'text/html'
Are you aware of the Groovy MarkupBuilder (https://docs.groovy-lang.org/latest/html/api/groovy/xml/MarkupBuilder.html)?
I would solve your question like:
def writer = new StringWriter()
def markup = new groovy.xml.MarkupBuilder(writer)
markup.html {
head {
title('Approval')
}
body {
mkp.yieldUnescaped('Approval is required. Please provide acceptance<br/>Visit the below link to approval/decline<br/><br/>Note This is system generated email')
p ('Regards,')
img(alt: 'your alt text', src: 'your image url')
p ('YamunaS')
}
}
writer.toString()
Which would result in:
<html>
<head>
<title>Approval</title>
</head>
<body>Approval is required. Please provide acceptance<br/>Visit the below link to approval/decline<br/><br/>Note This is system generated email
<p>Regards,</p>
<img alt='your alt text' src='your image url' />
<p>YamunaS</p>
</body>
</html>
And then rendered:
If you want to put the first sentences/lines into a paragraph or div container as well, just follow above way. A div-container would open a new closure again. For a full example including some stylesheets you can also have a look in one of my examples. It generates html dynamically and uses it in context of Springboot (which is probably too much for you now)
I am looking to update a specific div that can change depending on the stream.id.
I have the following :
ActionCable.server.broadcast('webconferencier_channel', participants_html: participants_html, stream_id: webconferencier.stream_id)
Where I do pass the stream_id.
I am looking to retrieve it in coffee file like this:
received: (data) ->
# Called when there's incoming data on the websocket for this channel
participantsHtml = data.participants_html
$('#show_participants' + data.stream_id).html(participantsHtml);
And then update the view as:
<div id="show_participants_#{<%= #stream.id %>}">
</div>
I can see the AC sending the div template with the other variables, but i cannot seem to retrieve and update it. I think my coffee syntax is incorrect.
In the view, the div id show up as :
<div id="show_participants_#{67089dbd-9826-41f2-97bc-b774b667ef66}">
</div>
with the UUID being the exact same string that i am passing through the coffee file.
Does anyone know how i could make this work please?
Thank you
You should remove curly braces and octothorp from div's id like show_participants_UUID.
You can add console.log to the coffee to see what's happening inside.
I stucked a day's trying to find a answer: is there a possibility with classic ASP, using MSXML2.ServerXMLHTTP.6.0 - to parse html code and extract a content of a HTML node by gived ID? For example:
remote html file:
<html>
.....
<div id="description">
some important notes here
</div>
.....
</html>
asp code
<%
...
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
objHTTP.Open "GET", url_of_remote_html, False
objHTTP.Send
...
%>
Now - i read a lot of docs, that there is a possibility to access HTML as source (objHTTP.responseText) and as structure (objHTTP.responseXML). But how in a world i can use that XML response to access content of that div? I read and try so many examples, but can not find anything clear that I can solve that.
First up, perform the GET request as in your original code snippet:
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "GET", url_of_remote_html, False
http.Send
Next, create a regular expression object and set the pattern to match the inner html of an element with the desired id:
Set regEx = New RegExp
regEx.Pattern = "<div id=""description"">(.*?)</div>"
regEx.Global = True
Lastly, pull out the content from the first submatch within the first match:
On Error Resume Next
contents = regEx.Execute(http.responseText)(0).Submatches(0)
On Error Goto 0
If anything goes wrong and for example the matching element isn't found in the document, contents will be Null. If all went to plan contents should hold the data you're looking for.
my function look like this:
void write (String message) {
query("#status").innerHTML = message;
query("#head").text = "Click me!";
}
all of them catch id and show text to web browser.
In general browser document model, innerHtml refers to all the internal HTML, whereas text just refers to the text values of the elements. innerHtml is often used by dhtml and Ajax to change a div, where text would be just to set the text value of a single element.
This is more explicitly illustrated when getting, rather than setting, i.e.
e.g. Given:
<div id="idName">
Text in the Div
<p id="anotherId">Inner P</p>
</div>
innerHtml returns
Text in the Div
<p id="anotherId">Inner P</p>
text returns :
Text in the Div
Inner P
If you try this:
String message = """<form method="get" action="#ref"><input name="first_name"/></p><input type="submit" value="Send"/></form>""";
write (message);
then you will appreciate the difference.
The innerHTML should operate an injection of code (an html form in the example) into the HTML page.
How could I correctly use the following?
{ bool submitter = value; }
...
#(submitter ? "" : #"<a href=""" + Url.Action(actionName, "Queue") + #""">")
<div>
...
</div>
#(submitter ? "" : "</a>")
My error is that the anchor tag definition is being outputed like it should be in a HTML code right to the web browser and instead of seeing a link around the <div> I see the <a href="... etc.
Why?
If you don't want that encoded, then you need to use the Raw extension method:
#Html.Raw(submitter ? "" : #"<a href=""" + Url.Action(actionName, "Queue") + #""">")
<div>
...
</div>
#Html.Raw(submitter ? "" : "</a>")
This is because you cannot put block level elements, like div, inside inline elements like a, unless you use HTML5. I guess from your description you aren't.
If you're checking in a browser DOM inspector, you will see your code looks something like this:
<div></div>
<div></div>
<a></a>
The alternative is to change your div to span and set display: block on it in CSS if you require.
Also, that kind of logic would be better placed in a ViewModel.
Solution that I've: found
#(new MvcHtmlString(#"blah blah"))