Angular Custom Directive

If you want to create a new re-usable tag, then you want to create a directive. Here is a sample directive:

//directives
// name it what will show as 'search-result' in html
// now you can put <search-result></search-result> (or <div search-result></div> in the html 
myApp.directive("searchResult",function(){
    return{
        template: '<a href="#"  class="list-group-item><h4 class="list-group-item-heading">Doe,John</h4><p class="list-group-item-text">555 Main St., New York, NY 11111</p></a>'
        , replace: true     //will replace the original tag 
                            //rather than putting this html inside existing tag
        
    }
});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s