admin管理员组文章数量:1415111
I can't make the simplest of directives work in my AngularJS + Coffeescript project.
I have this code in directives.coffee:
'use strict'
app_name = "myApp"
app = angular.module "#{app_name}.directives", []
# Directive to include the version number of my project
app.directive 'appVersion', [
'version', (version) ->
(scope, element, attrs) ->
element.text version
]
# Hello world directive
app.directive 'hello', () ->
restict: 'E'
template: '<div>Hello World</div>'
And in my template, when I do
<span app-version></span>
<hello></hello>
then the version number appears (0.1), showing that the first directive works properly, but the tag does not get replaced by anything.
Any idea what I did wrong?
I also tried this, which didn't work either:
# Hello world directive
app.directive 'hello', ->
class Habit
constructor: ->
restict: 'E'
template: '<div>Hello World</div>'
I can't make the simplest of directives work in my AngularJS + Coffeescript project.
I have this code in directives.coffee:
'use strict'
app_name = "myApp"
app = angular.module "#{app_name}.directives", []
# Directive to include the version number of my project
app.directive 'appVersion', [
'version', (version) ->
(scope, element, attrs) ->
element.text version
]
# Hello world directive
app.directive 'hello', () ->
restict: 'E'
template: '<div>Hello World</div>'
And in my template, when I do
<span app-version></span>
<hello></hello>
then the version number appears (0.1), showing that the first directive works properly, but the tag does not get replaced by anything.
Any idea what I did wrong?
I also tried this, which didn't work either:
# Hello world directive
app.directive 'hello', ->
class Habit
constructor: ->
restict: 'E'
template: '<div>Hello World</div>'
Share
Improve this question
asked Nov 15, 2013 at 19:28
mascipmascip
1,3671 gold badge14 silver badges16 bronze badges
2 Answers
Reset to default 7You can also write your Angular Directive in CoffeeScript like this which I think is cleaner:
class MyDirective
constructor: (myService) ->
// Constructor stuff
@controller = MyController
@controllerAs = 'ctrl'
restrict: 'E'
replace: true
scope:
attributeStuff: '='
link: (scope, element, attr) ->
angular.module('my_module').directive 'MyDirective', (myService) ->
new MyDirective(myService)
You have a typo:
restict: 'E'
should be
restrict: 'E'
Working code: http://plnkr.co/edit/8TifpS2EmYPLo4wl7YtK?p=preview
本文标签: javascriptAngularJSCoffeescript39Hello World39 directive not workingStack Overflow
版权声明:本文标题:javascript - AngularJS + Coffeescript - 'Hello World' directive not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745198980a2647278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论