Referenciando un elemento con Template Variable en Angular

Cuando trabajamos sobre un elemento HTML de un template, existe una alternativa a utilizar el objeto $event sobre la función en la que trabajaremos con el evento, dicha alternativa recibe el nombre de Template Variable.

Ejemplo con Event binding

Si por ejemplo quisiera obtener el valor de un input mediante el objeto $event, podría hacer algo similar a lo siguiente:

Ejemplos con Template Variable

En cambio, Template Variable (o variable de referencia de plantilla) nos va a permitir hacer referencia hacía elemento del DOM, sobre el que estamos trabajando sin tener que pasarle un $event. Vamos a ver un ejemplo:

Para realizar un Template variable utilizamos el símbolo de # dentro de la plantilla.

Vamos a ver un ejemplo:

Si nos fijamos estamos accediendo al elemento con tan solo poner la almohadilla # junto a un nombre y pasandoselo por parametro a la función que ejecutaremos cuando se realice el evento. El resultado será:

Si queremos acceder al valor, podriamos utilizar como hemos hecho anteriormente:

O bien, utilizar el nombre del template acompañado de value:

Ambos nos darán el mismo resultado que será:

Ejercicio con Template View

Vamos a hacer un input de tipo password en el que solamente cuando introduzcamos un valor nos aparezca el botón de ver password y si lo pulsamos se muestre un alert con la contraseña. En el caso de que borremos la contraseña al completo, el botón desaparecerá y mostraremos un mensaje la consola del navegador.

Un ejemplo de esto podría ser:

Nos aparece solo el input (sin el botón)

Introducimos un password y nos ofrece la posibilidad de ver dicho password:

Pulsamos el botón y nos muestra el password:

Ocultamos el botón en el caso que no tengamos un password añadido y además mostramos un mensaje por consola:

Esto es todo, espero que os haya gustado, como habéis visto, Template View, nos proporciona otra manera de trabajar con los eventos sin utilizar el objeto $view. Un saludo

61 comentarios

  1. I like what you guys are usually up too. Such clever work and reporting!
    Keep up the great works guys I’ve included you guys to my own blogroll.

  2. Hi there would you mind letting me know which web host you’re using?
    I’ve loaded your blog in 3 completely different web browsers and I must say this
    blog loads a lot faster then most. Can you recommend
    a good web hosting provider at a reasonable price?
    Kudos, I appreciate it!

  3. Spot on with this write-up, I truly believe that this site needs much more attention. I’ll probably be back again to read through
    more, thanks for the info!

  4. With havin so much content do you ever run into any issues of plagorism or copyright violation? My site has a lot of exclusive
    content I’ve either written myself or outsourced but it
    seems a lot of it is popping it up all over the web without my agreement.

    Do you know any methods to help prevent content from being ripped
    off? I’d definitely appreciate it.

  5. I’m gone to convey my little brother, that he should also pay a
    visit this web site on regular basis to take updated from newest news.

    Also visit my blog post –

  6. Having read this I believed it was very enlightening. I appreciate you spending some
    time and energy to put this information together.
    I once again find myself spending way too much time both reading and posting comments.
    But so what, it was still worth it!

  7. Good day! This is my first visit to your blog!
    We are a group of volunteers and starting a new initiative in a community in the same niche.
    Your blog provided us useful information to work on. You have
    done a extraordinary job!

  8. I had been honored to get a call from my friend immediately he uncovered the important ideas shared on the
    site. Examining your blog article is a real brilliant experience.

    Thank you for taking into consideration readers much like
    me, and I hope for you the best of achievements being a professional in this

    Feel free to surf to my website: Testo Bull Capsules

  9. I am genuinely delighted to glance at this weblog posts which carries
    tons of helpful information, thanks for providing these data.

  10. Utterly written subject material, Really enjoyed looking through.

    my website Brilliance Keto

  11. Woh I enjoy your posts, saved to fav!

    Feel free to surf to my blog post – Imarais Beauty

  12. My brother suggested I might like this website. He was
    entirely right. This post actually made my day. You cann’t
    imagine simply how much time I had spent for this info!

  13. Hey there! This is my 1st comment here so I
    just wanted to give a quick shout out and tell you I really enjoy reading through your
    blog posts. Can you recommend any other blogs/websites/forums
    that deal with the same topics? Many thanks!

  14. Hi every one, here every one is sharing these kinds of know-how, therefore it’s pleasant
    to read this webpage, and I used to visit this webpage all the time.

    Feel free to visit my web page;u=150831

  15. Thanks for this post, I am a big fan of this website would like to go
    along updated.

    My blog post: Total Keto 365 Side Effects

  16. I’m truly enjoying the design and layout of your site. It’s a very
    easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme?

    Superb work!

    My webpage :: Moskiller

  17. You’re so awesome! I do not believe I have read through a single thing like that before.
    So wonderful to discover someone with a few genuine thoughts on this issue.
    Seriously.. many thanks for starting this up.

    This site is something that is needed on the internet, someone with a bit of originality!

  18. This article is truly a nice one it assists new the web viewers, who are wishing in favor
    of blogging.

  19. As a Newbie, I am continuously exploring online for articles
    that can benefit me. Thank you

    Stop by my homepage; Keto Complete Pills

  20. I pay a quick visit day-to-day a few websites and information sites to read articles, except this website offers quality based posts.

    my page: Infinuity CBD

  21. You’re so cool! I don’t suppose I’ve truly read through something like this before.

    So wonderful to find another person with a few original thoughts on this topic.
    Really.. thanks for starting this up. This web site is one thing that’s needed on the web, someone with a bit of originality!

    Also visit my webpage: Lithederm Revitalizing Moisturizer

  22. Enjoyed reading this, very good stuff, appreciate it.

    Take a look at my blog – Testo Bull Review

  23. Undeniably believe that which you stated. Your
    favorite reason appeared to be on the internet the simplest thing to be aware of.
    I say to you, I definitely get irked while people consider worries that they plainly do not know about.
    You managed to hit the nail upon the top and defined out the whole thing
    without having side-effects , people can take a signal. Will probably be back to get more.

  24. Greetings! Very useful advice within this post! It’s the little
    changes which will make the greatest changes. Many thanks for sharing!

    Take a look at my site – Mora

  25. Keep on writing, great job!

    Take a look at my website – Trim Tone Side Effects (

  26. I like this weblog it’s a master piece! Glad I discovered this on google.

    Feel free to surf to my web site … Dermal Pearle Reviews

  27. Excellent article! We will be linking to this particularly great post on our site.
    Keep up the good writing.

    Also visit my web page … Dermal Pearle Cream

  28. I like this web blog it’s a master piece! Glad I detected this on google.

    Feel free to visit my web page; Dermal Pearle Ageless Moisturizer

  29. Absolutely composed content, Really enjoyed reading through.

    My web site; Evo Naturals Hemp Gummies (

  30. Hi! Someone in my Myspace group shared this site with us so I came to check it
    out. I’m definitely loving the information. I’m bookmarking and will be
    tweeting this to my followers! Excellent blog and outstanding style
    and design.

    Check out my blog – Natural Burn Keto Review

  31. Thank you, I have recently been searching for
    info about this topic for ages and yours is the greatest I’ve came
    upon so far. However, what about the conclusion? Are you sure about
    the supply?

    Here is my homepage; Keto Speed Diet

  32. This piece of writing will help the internet visitors
    for setting up new webpage or even a blog from start to end.

    Take a look at my blog; Hedofirm 360 Review

  33. Its like you read my mind! You appear to know a lot about
    this, like you wrote the book in it or something. I think that you could do
    with some pics to drive the message home a bit, but other than that, this is fantastic blog.

    An excellent read. I’ll definitely be back.

  34. Hurrah, that’s what I was searching for, what a stuff!
    present here at this web site, thanks admin of this web site.

    Also visit my site: Oracle Leaf Gold CBD Review

  35. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Any way I will be subscribing to your augment and even I achievement you access consistently

  36. I think the admin of this web page is in fact working hard for his site,
    as here every information is quality based material.

    My blog post:

  37. It’s enormous that you are getting thoughts from this piece of writing as
    well as from our discussion made at this place.

  38. Thank you for any other informative blog. Where else
    could I am getting that type of info written in such an ideal approach?
    I have a mission that I’m simply now running on, and I’ve been on the
    glance out for such info.

    Also visit my web page Ilok Air Portable Air Conditioner

  39. Thank you for being the tutor on this theme. I enjoyed the article very much and most of all appreciated how
    you handled the areas I regarded as controversial.
    You happen to be always incredibly kind towards readers really like me and aid me
    in my life. Thank you.

    My blog; Ardent Male Enhancement Ingredients

  40. Hello There. I found your blog using msn. This is an extremely well written article.
    I’ll make sure to bookmark it and return to read more of your
    useful information. Thanks for the post. I’ll definitely comeback.

    Feel free to surf to my homepage Testo Bull Capsules

  41. Hiya, I am really glad I’ve found this info. Nowadays bloggers publish just about gossips and net and this is really annoying.

    A good blog with exciting content, this is what I need.
    Thank you for keeping this site, I’ll be visiting it.
    Do you do newsletters? Can’t find it.

    Also visit my web blog Monte

  42. What’s up, constantly i used to check website posts here in the early hours in the daylight, as i enjoy to find out more and more.

    Also visit my blog :: Tundra Breeze Air Conditioner Review

  43. I gotta bookmark this web site it seems very useful invaluable.

    Feel free to visit my web page … Gold Leaf CBD Reviews

  44. Very efficiently written information. It will be helpful to everyone who utilizes it, including myself.
    Keep doing what you are doing – can’r wait to read more posts.

    my page Hedofirm 360 (

  45. Wohh exactly what I was searching for, thank you for posting.

    Feel free to surf to my web page: Kristie

  46. I enjoy what you guys are usually up too. This sort of clever work and reporting!
    Keep up the superb works guys I’ve added you guys to my own blogroll.

    Feel free to surf to my web-site: Ilok Air Reviews

  47. Hello! Someone in my Myspace group shared this website with us so I came to check it out.
    I’m definitely enjoying the information. I’m book-marking and will
    be tweeting this to my followers! Exceptional blog and terrific design and style.

  48. I went over this web site and I believe you have
    a lot of superb information, saved to bookmarks (:.

    Check out my blog post: Moskiller

  49. Link exchange is nothing else however it is just placing the other person’s website
    link on your page at suitable place and other person will also
    do same for you.

    My site: Cognitive IQ Ingredients

  50. Fantastic goods from you, man. I have understand your stuff
    previous to and you’re just extremely wonderful. I actually like what
    you have acquired here, certainly like what you
    are stating and the way in which you say it. You make
    it enjoyable and you still take care of to keep
    it smart. I cant wait to read far more from you.
    This is actually a terrific website.

    My web blog :: VirgoFX

  51. Hello, I enjoy reading all of your article post. I like to write a little comment to support you.

    Here is my web blog ::

  52. Only wanna input on few general things, The website layout is perfect,
    the content is rattling great :D.

    Also visit my website – Vigalix

  53. I got what you mean, thank you for putting up. Woh I am delighted to find this website through google.

    My homepage: Testo Bull Review

  54. With havin so much written content do you ever run into any
    problems of plagorism or copyright violation? My website has a lot of exclusive content I’ve either authored myself or
    outsourced but it appears a lot of it is popping it up all over the internet without my authorization. Do you know any methods to help prevent
    content from being stolen? I’d genuinely appreciate it.

  55. Hi to every body, it’s my first pay a quick visit of this blog; this web site carries amazing and truly excellent material in support of visitors.

    My page; Maritza

  56. I’ve recently started a site, the information you offer on this
    web site has helped me greatly. Thank you for
    all of your time & work.

    Review my homepage ::

  57. Thanks for finally writing about > Referenciando un elemento con Template Variable
    en Angular – Java desde 0 < Loved it!

    my webpage – Dermal
    Pearle Review

  58. Thank you for sharing with us, I conceive this website really stands out :D.

    My webpage; Yoni Pur Review

  59. Hi i am kavin, its my first occasion to
    commenting anywhere, when i read this piece of writing i thought i could also create comment due
    to this sensible article.

    Here is my website :: Mega XL Male Enhancement

  60. What i do not understood is actually how you’re not really much
    more neatly-favored than you might be right now. You are very intelligent.
    You recognize thus considerably in relation to this subject, made me personally consider it
    from a lot of numerous angles. Its like men and women are not involved until it’s one
    thing to accomplish with Girl gaga! Your individual stuffs excellent.

    All the time take care of it up!

    Have a look at my blog – Kirby

  61. I’m impressed, I must say. Rarely do I come across a blog that’s both educative and
    engaging, and without a doubt, you have hit the nail on the
    head. The issue is something too few people are speaking intelligently
    about. I am very happy I stumbled across this in my search for something concerning this.

    Visit my page –

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

La Ley 34/2002 nos obliga a avisarte de que usamos cookies propias y de terceros con objetivos estadísticos y de sesión y para mostrarte la 'publi' que nos da de comer. Tranquilo, este mensaje solo sale una vez. Más información

Java desde 0 comunica a los usuarios, a través de este aviso, que puede utilizar cookies cuando el usuario navega por las diferentes pantallas y páginas del sitio. Durante el uso de nuestra página Web usted acepta y autoriza expresamente el uso de cookies, de acuerdo con nuestra Política de Privacidad. Este sitio web utiliza las siguientes cookies propias: - Cookies de sesión, para garantizar que los usuarios que escriban comentarios en el blog sean humanos y no aplicaciones automatizadas. De esta forma se combate el spam. Este sitio web utiliza las siguientes cookies de terceros: - Google AdManager y AdSense: Utiliza cookies para mejorar la publicidad. Entre otros fines, suelen utilizarse para segmentarla según el contenido que sea relevante para los usuarios o su ubicación, mejorar los informes de rendimiento de las campañas y evitar mostrar anuncios que los usuarios ya hayan visto. Las cookies no contienen información personal identificable. Consulta cómo utiliza Google la información de sitios web o aplicaciones. y cómo bloquear determinados anuncios. - Google Analytics: Almacena cookies para poder elaborar estadísticas sobre el tráfico y volumen de visitas de esta web. Al utilizar este sitio web está consintiendo el tratamiento de información acerca de usted por Google. Por tanto, el ejercicio de cualquier derecho en este sentido deberá hacerlo comunicando directamente con Google. - Redes sociales: Cada red social utiliza sus propias cookies para que usted pueda pinchar en botones del tipo Me gusta o Compartir.