angularjs - Angular directive calls function passed by isolated scope (ngclickfunction:'&') works fine but browser gives: Uncaught SyntaxError: Unexpected token } -
i have created button directive want reuse along site.
daniboomerangdirectives.directive('button', function() { return { restrict: 'ea', scope: { ngclickfunction: '&' }, template: function (elem, attrs) { ... if (attrs.onclick == 'function') { link = '<a id="button-link" href="" ng-click="ngclickfunction()">' + linkcontent + '</a>'; } ... return '<div id="button-wrapper"><div id="button">' + link + '</div></div>'; } }; });
the idea ng-click function passed 1 uses button directive, , button directive calls function passed parent via ngclickfunction: '&' when user clicks in <a>
element of button
.directive('daniboomerangintro', function($timeout, $rootscope, $compile) { return { restrict: 'a', templateurl: 'views/intro.html', link: function (scope, element, attrs) { var introbuttonstartapphtml = '<div button id="start-button" contenttype="text" text="start" statepressed="false" onclick="function" ngclickfunction="startapp()"></div>'; introcenter.append(introbuttonstartapphtml); $compile(introcenter)(scope); scope.startapp = function(){ ... }
the thing works fine. parent scope function startapp()
works fine, executed correctly. however, this:
on safari: syntaxerror: unexpected token '}' (anonymous function)
on chrome: uncaught syntaxerror: unexpected token } (index):2
on firefox: 'syntaxerror: function statement requires name (localhost:8080:1:8)
if put ng-click in parent directive @ button directive element don´t browser error.
var introbuttonstartapphtml = '<div button id="start-button" contenttype="text" text="start" statepressed="false" ng-click="startapp()"></div>';
my problem here don´t know how keep looking it. there no file debug, line of code triggers error... how proceed?
thanks
it seems (frankly, did not analyse code, glimpsed on - might wrong) error triggered fact onclick
attribute (parsed browser javascript code) contains reserved keyword: function
in context not parseable. instantiation of dom string end in exception. since seem using keyword sort of magic string, why don't try change it, either other name (then javascript should parse, although not execute) or change attribute name else?
Comments
Post a Comment