AngularJS + Coffeescript - “Hello World"指令不起作用 [英] AngularJS + Coffeescript - 'Hello World' directive not working

查看:25
本文介绍了AngularJS + Coffeescript - “Hello World"指令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在我的 AngularJS + Coffeescript 项目中使用最简单的指令.

I can't make the simplest of directives work in my AngularJS + Coffeescript project.

我在directives.coffee中有这个代码:

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>

然后出现版本号 (0.1),表明第一个指令正常工作,但标签没有被任何东西替换.

then the version number appears (0.1), showing that the first directive works properly, but the tag does not get replaced by anything.

知道我做错了什么吗?

我也试过这个,但也没有用:

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>'

推荐答案

你有一个错字:

restict: 'E'

应该是

restrict: 'E'

工作代码:http://plnkr.co/edit/8TifpS2EmYPLo4wl7YtK?p=preview

这篇关于AngularJS + Coffeescript - “Hello World"指令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆