Max Song
Max Song

Reputation: 1687

Coffeescript + Angular Directive Syntax Error

Im trying to write a directive in Angular in Coffeescript and am running into difficulties. Here is my directive code:

myApp.directive('myDirective3', () -> 
    #directive is used in ng-repeat

        return {

            scope: '@'
            restrict: 'E'
            template: 'My name is {{person.first}} {{person.last}}',
            link: (scope, element, attrs) -> 
                console.log("scope inside linking function")
                console.log(scope)


            }
        )

When I try to compile it, coffeescript is throwing an error:

error: unexpected :
            link : (scope,element,attributes) ->
                 ^^

I have looked several examples of how link is defined elsewhere and it seems precisely to use this : to denote key/value relationship in the dictionary to return. Is there something I'm missing here?

Commenting out the link : results in a working script

Thanks!

Upvotes: 0

Views: 112

Answers (1)

Tien Nguyen
Tien Nguyen

Reputation: 599

I think you have tabs problems

myApp.directive('myDirective3', () ->
#directive is used in ng-repeat

    return {

        scope: '@'
        restrict: 'E'
        template: 'My name is {{person.first}} {{person.last}}',
        link: (scope, element, attrs) ->
            console.log("scope inside linking function")
            console.log(scope)


    }
)

should be compiled

Upvotes: 1

Related Questions