我今天刚开始玩 AngularJS 并且卡住了。请原谅咖啡稿和哈姆尔。
# some-js-file.js.coffee
app.directive "sr", ->
restrict: "C"
replace: true
transclude: true
scope:
serviceRequest: "@servReq"
template: "<div>" + "<div class=\"name\">{{service_request}}</div>" + "<div class=\"body\" ng-transclude></div>" + "</div>"
link: (scope, element, attrs) ->
scope.$watch 'serviceRequest', (serviceRequest) ->
console.log scope.serviceRequest, serviceRequest
# cool stuff
# index.html.haml
# more cool stuff...
.row{'ng-repeat' => 'service_request in service_requests'}
.sr{'serv-req' => '{{service_request}}'}
{{service_request.description}}
循环和基本模板正在显示,除了 {{service_request}} 表达式没有被评估 - 只是空白。
您会注意到,在“链接:”部分中,我必须 $watch 才能使 console.log 工作的范围——它也没有评估 serviceRequest。这是怎么回事?
谢谢!!