Skip to content Skip to sidebar Skip to footer

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.

  1. Directive element method should be

    remove-parent-div="removeParentDiv(index)"
  2. and while calling it from directive, by having json structure, where index is nothing but parameter and datasource_index is value of it.

    scope.removeParentDiv({index: datasource_index});
    
  3. Do run digest cycle after calling scope.deleteDatasource(scope.datasourceIndex); method from click event so that it will update scope 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"