0

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!

3
  • Is it because of the comma you placed at the end of template? Commented Mar 20, 2015 at 14:42
  • What is the use of the "->" at the end of that line? I'd assume it's a lambda syntax, like any other language, but does the basic link synatx work? Try link: function($scope, element, attrs) {console.log("scope inside linking function") console.log(scope)} Commented Mar 20, 2015 at 14:46
  • Also, are there suppose to be commas at the end of each property "scope: @,"? Commented Mar 20, 2015 at 14:50

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Holy mackerel - you are right. it compiles! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.