Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test Karma Jasmine SyntaxError: Parse error on "&" Angular Directive binding #15

Open
ericjames opened this issue Feb 17, 2016 · 0 comments

Comments

@ericjames
Copy link

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() {
    return {
        restrict: 'E',
        replace: true,
        template: '<a href="#">&#x2715</a>',
        scope: {
            datasourceIndex: '@',
            removeParentDiv: '&'
        },
        link: link
    };

    function link(scope, element, attr) {

        element.bind('click', function(event) {
            event.preventDefault();
            scope.deleteDatasource(scope.datasourceIndex);
        });

        // Notify parent directive
        scope.deleteDatasource = function(datasource_index) {
            // conditional stuff that happens not included
            // {} required for passing values to "&" parent scope method
            scope.removeParentDiv({datasource_index});
        };
    }
}]);

HTML

<parent-div ng-repeat> // this is just a mockup not literal
<datasource-delete-btn datasource-index="{{$index}}" remove-parent-div="removeParentDiv()"></datasource-delete-btn>
</parent-div>

The parent div of the ng-repeat that passes removeParentDiv

// parentDiv directive has this
        scope.datasources = [];
        scope.removeDatasourcePicker = function(index) {
            scope.datasources.splice(index, 1);  // ie take it out
        };

It seems the problem is that Jasmine does not like the { }. Removing the brackets results in the test going through (with typical errors since & requires {}).

@ericjames ericjames reopened this Feb 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant