I'd say start small and then build up to the more complex directives. 
 Here's the simplest one I've built.  It only requires a returning an 
object with a linking function.  Following the syntax pattern, all you have 
to worry about is that the linking function is called when angular compiles 
the directive on your element.

.directive('fallbackSrc',[ 
function(){
return {
link: function(scope,element,attrs){
element.bind('error', function(e){
element.attr('src', attrs.fallbackSrc)
})
}
}
}
])

<img src="/some/image.png" fallback-src="/another/fail-safe-image.png">

Inside the function, "element" is a jquery-lite wrapped object so jquery's 
functionality is already there.  All it does is on the error event, is set 
the element's src attribute to the fallbackSrc attribute.

You can keep reading tutorials until your heart is content, but I gained 
real understanding by jumping in, copying others ideas, then tweaking it, 
etc, until the pieces bean to make more sense.

Good luck!




On Wednesday, April 15, 2015 at 5:54:33 PM UTC-6, Christian Nwamba wrote:
>
> Hi peeps!
>
> I feel am the biggest lover of angular and it's my favourite developer 
> tool. The only problem is that I get limited when I want to use external or 
> custom tools and make use of a reusable component.  I know this is my 
> inability to harness the potentials of directives but I have been trying my 
> best but not just getting it right yet.
>
> Can anyone help me with perfect article(s) that will make angular 
> directives be my best friend.
>
> Definitely you should know I have seen the tutorial and examples on 
> angular website.
>
> Thanks and Regards!
> Chris
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to