AngularJS + CoffeeScript的 - '你好世界'指令不工作 [英] AngularJS + Coffeescript - 'Hello World' directive not working

查看:130
本文介绍了AngularJS + CoffeeScript的 - '你好世界'指令不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能让简单的指令在我AngularJS + CoffeeScript的项目。

我在这directives.coffee code:

 使用严格
APP_NAME =对myApp
应用= angular.module#{} APP_NAME .directives,[]#指令,包括我的项目的版本号
app.directiveappVersion,[
'版本',(版本) - GT;
    (范围,元素,ATTRS) - GT;
    element.text版本
]#世界,你好指令
app.directive'你好',() - GT;
    restict:'E'
    模板:'< D​​IV>的Hello World< / DIV>'

在我的模板,当我做

 <跨度的应用程序版本>< / SPAN>
<&打招呼GT;< /你好>

然后出现的版本号(0.1),这表明第一指示正常工作,但该标记不会获得通过任何取代。

任何想法,我做错了什么?

我也试过了,没有工作之一:

 #世界,你好指令
app.directive'你好', - >
    一流的习惯
        构造函数: - >
            restict:'E'
            模板:'< D​​IV>的Hello World< / DIV>'


解决方案

您有一个错字:

  restict:'E'

 限制:'E'

工作code: http://plnkr.co/edit/8TifpS2EmYPLo4wl7YtK p = preVIEW

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

解决方案

You have a typo:

restict: 'E'

should be

restrict: 'E'

Working code: http://plnkr.co/edit/8TifpS2EmYPLo4wl7YtK?p=preview

这篇关于AngularJS + CoffeeScript的 - '你好世界'指令不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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