Angular Custom widget issue.

27 views
Skip to first unread message

Wes

unread,
Feb 9, 2012, 7:12:20 PM2/9/12
to AngularJS
I am trying to learn about using the custom widgets, and want to use
Angular to allow us to sub class html elements like buttons and check
boxes to do custom behaviors. I have seen many discussions of setting
up the widget like this:

angular.widget('@my:button', function(expression, compileElement) {
var compiler = this;
compiler.descend(true);
compileElement.append("<button ng:click='update()'>Increment</
button>");

});


however, I am trying to get it working when the click handler is
declared in html like this:
<my:button label='hola test button' ng:click='MyCustomFunction()'></
my:button>

function MyCustomFunction() {
alert('i work');
}

angular.widget('@my:button', function(expression, compileElement) {
var compiler = this;
compiler.descend(true);
compileElement.append("<button>Increment</button>");
});

is it possible to declare the click callback in html instead at the
compiletime of the widget?

thanks
wes

Vojta Jina

unread,
Feb 10, 2012, 3:47:36 AM2/10/12
to ang...@googlegroups.com
Yes, with 0.10.6 you have to use directive - if you use attribute widget (@my:button), this attr widget is executed first and the rest of the stuff is ignored - that's why ng:click does not work.

Wait for 0.10.7 and new compiler, it's gonna be much simplier (everything is directive) and much much powerfull, so this will work out of the box...

V.
Reply all
Reply to author
Forward
0 new messages