Unit Test Karma Jasmine Syntaxerror: Parse Error On "&" Angular Directive Binding
I get SyntaxError: Parse error at my directive line where I want to use a '&' one-way binding from a parent directive's method myApp.directive('datasourceDeleteBtn', [function(
Solution 1:
You are getting error because you are passing json in wrong format in method
You have not called method passed in directive scope removeParentDiv: '&'
correctly from directive. As you are only doing scope.removeParentDiv({datasource_index});
which would not pass index parameter to the method.
For make it working, you need to do couple of changes.
Directive element method should be
remove-parent-div="removeParentDiv(index)"
and while calling it from directive, by having json structure, where
index
is nothing but parameter anddatasource_index
is value of it.scope.removeParentDiv({index: datasource_index});
Do run digest cycle after calling
scope.deleteDatasource(scope.datasourceIndex);
method fromclick
event so that it will updatescope
binding.element.bind('click', function(event) { event.preventDefault(); scope.deleteDatasource(scope.datasourceIndex); scope.$apply(); //to run digest cycle, to keep binding in sync });
Post a Comment for "Unit Test Karma Jasmine Syntaxerror: Parse Error On "&" Angular Directive Binding"