[Angular Directive] 2. Add Inputs to Angular 2 directives

Source: Internet
Author: User
Tags angular 2 directives

The decorator allows you-pass values into your so, can change the value of the the Directive each time @Input @Directive That's it is used. Using @Input makes your directives much more flexible and reusable so they can adapt to many different situations.

 Import {Directive, Input, hostbinding} from     @angular/core       [getinput]   " }) export  class   Getinputdirective {@Input ( "  getinput   "  get   InnerText () { return  this   .input; } constructor () {}}  
<span [getinput]="' something '">i am a span</span>

[GetInput] means we have a prop in our directive call ' GetInput ', go and find it and set the value as ' something '.

It'll only show "something" on the page. Here we pass value to the directive and then reflect the input value to the Host element's InnerText by using getter.

[Angular Directive] 2. Add Inputs to Angular 2 directives

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.