Angularjs + CoffeeScript - 'Hello World'지시문이 작동하지 않습니다.
-
20-12-2019 - |
문제
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'
.
다른 팁
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)
. 제휴하지 않습니다 StackOverflow