I recently dove into AngularJS and hit a roadblock. Excuse the coffeescript and haml mix.
# 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}}
Although the loop and basic template are rendering, the {{service_request}} expression remains unaevaluated - just empty.
In the 'link:' section, you'll see that I had to $watch the scope for console.log to function - it wasn't assessing serviceRequest either. What gives?
Thanks!!