【问题标题】:angularjs "hello world" directive + coffeescript not workingangularjs“hello world”指令+咖啡脚本不起作用
【发布时间】:2014-05-27 10:25:09
【问题描述】:

假设我有我的指令

@directivesModule = angular.module('myApp.directives', [])

在directive.coffee中

directivesModule.directive 'showAuthorLogin', () ->
    restrict: 'E'
    template: '<div>Hello World</div>'

index.html:

<span showAuthorLogin></span>

为什么什么都没有显示?

【问题讨论】:

  • 编译出来的javascript是什么样子的?
  • 在 jsfiddle 上看起来像这样 jsfiddle.net/CXgw7
  • 啊你的 html 需要是 。 Angular 将它从驼峰式转换而来。我在答案中发布了一个示例
  • 谢谢,没想到

标签: angularjs


【解决方案1】:

restrict: 'E' 表示指令必须是一个元素。所以你可以将指令更改为restrict: 'A',或者你可以将你的html更改为:&lt;showAuthorLogin&gt;&lt;/showAuthorLogin&gt;

这是一个在 JSFiddle 上工作的示例:http://jsfiddle.net/X6A7M/

【讨论】:

    猜你喜欢
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2018-01-25
    • 1970-01-01
    • 2013-02-15
    • 2015-08-03
    相关资源
    最近更新 更多