1

I am working a project using Psiturk, which uses the jinja2 syntax. I wrote my questionnaire in Angular. I am getting an error when I try to reference $index in the html directly. The error log shown below shows the issue as the use of $ (dollar sign) in the html. If there a way to make an alias for built in functions in Angular? Thanks

sample code:

<div id="container-exp" ng-app="app" ng-controller="PaginationController">
    <fieldset id='top' name='{{page}}' ng-repeat="tweet in pagedData | limitTo:pageSize">
      <h3>{{tweet.Tweet}}</h3>
      <!--repeates for every item in list-->
      <label>sample label 1<input class="radiobttn" ng-model="Responses[tweet.Tw_ID+$index]" id='{{currentPage}}_{{$index}}_1'  type='radio' value='1'  /></label>
      <label>sample label 2<input class="radiobttn" ng-model="Responses[tweet.Tw_ID+$index]" id='{{currentPage}}_{{$index}}_1'  type='radio' value='2'  /></label>
    </<fieldset>
</div>

The error I am getting:

File "/templates/stage.html", line 26, in template

<label>
    sample label 1
    <input class="radiobttn" ng-model="Responses[tweet.Tw_ID+$index]" 
    id='{{currentPage}}_{{$index}}_1' name='{{currentPage}}_{{$index}}_21' 
    type='radio' value='1'  />
</label\>

TemplateSyntaxError: unexpected char u'$' at 884

Juan
  • 4,910
  • 3
  • 37
  • 46
Mafuchi
  • 11
  • 1

1 Answers1

0

I don't think you can do that in AngularJS. But you might be able to change the way jinja2 templates are written. Have a look at the following question - Is it possible to use Angular with the Jinja2 template engine? - you might find some answers there on how to do that. The point number 3 seem particularly helpful in your case.

Vladimir Zdenek
  • 2,270
  • 1
  • 18
  • 23
  • Thanks for the suggestion. When tried, this does solve the error, but the html is passed without any angular attached (no matter where I put the %raw variable). If I put it within the inputs, and leave the ng-repeat out, I get an error asking to define 'tweet' (which is pulled from angular). So I think I will have to just forgo Psiturk (jinja2) and create my own php solution to work with angular. – Mafuchi May 25 '17 at 17:33