Coffeescript + Angular Directive语法错误

时间:2015-03-20 14:30:54

标签: angularjs coffeescript

我试图在Coffeescript的Angular中编写一个指令并遇到困难。这是我的指令代码:

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)


            }
        )

当我尝试编译它时,coffeescript会抛出一个错误:

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

我已经看了几个关于如何在其他地方定义链接的例子,似乎正好使用它:表示要返回的字典中的键/值关系。这里有什么我想念的吗?

评论link :会导致工作脚本

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为你有标签问题

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)


    }
)

应编译