문제

angularjs + coffeescript 프로젝트에서 가장 단순한 지시문을 일할 수 없습니다.

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

및 내 템플릿에서, 내가 할 때

<span app-version></span>
<hello></hello>
.

그런 다음 버전 번호가 나타나 (0.1)이면 첫 번째 지시문이 제대로 작동하지만 태그가 아무 것도 대체되지 않습니다.

내가 무엇을 잘못했는지 어떤 생각?

나는 이것도 이것을 시도했다.

# Hello world directive
app.directive 'hello', ->
    class Habit
        constructor: ->
            restict: 'E'
            template: '<div>Hello World</div>'
.

도움이 되었습니까?

해결책

오타 :

restict: 'E'
.

이어야합니다
restrict: 'E'
.

작업 코드 : http://plnkr.co/edit/8tifps2emplo4wl7ytk?p=preview

다른 팁

CoffeEScript에 각도 지침을 작성할 수도 있습니다.

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)
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top