1

I am using haml templates with angular js. While template rendering i want to create a function call on div using ng-click. It is working fine without parameter but when I am passing a parameter to function it behaving like as below for two cases.

%div.sitesContainer
  .wrapper
    %div.site{"ng-repeat"=>"site in sites",'ng-click'=>"siteBlockclick({{site.id}})"}
      %span
        {{site.name}}

Then it is giving me error Syntax Error: Token 'site.id' is unexpected But I inspect div it is showing ng-click="siteBlockclick(BWN)" means value is coming but single quotes are missing.

%div.sitesContainer
  .wrapper
    %div.site{"ng-repeat"=>"site in sites",'ng-click'=>"siteBlockclick('{{site.id}}')"}
      %span
        {{site.name}}

If I given single quotes it is printing then it is making call like ng-click="siteBlockclick('{{site.id}}')"

How should I concat it so that It will work for me ?

I want something like ng-click="siteBlockclick('BWN') after inspect

Any help appreciated.

Swapnil Patil
  • 971
  • 2
  • 18
  • 41
  • in HAML the bracket has meaning... maybe you can escape it: http://haml.info/docs/yardoc/file.REFERENCE.html#escaped-filter – Jorg Jun 26 '14 at 08:02

1 Answers1

1

Inside an ng-click, you don't need to interpolate (use {{ }}.

So, this should work for you:

%div.sitesContainer
  .wrapper
    %div.site{"ng-repeat"=>"site in sites",'ng-click'=>"siteBlockclick(site.id)"}
      %span
        {{site.name}}

the ng-repeat creates each site in scope and the ng-click accesses that scope directly.

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132