I am trying to set some text on a data attribute that is used in a directive call:
<textarea class="pagedown-admin wmd-preview-23"
data-modal="modal"
data-pagedown-admin
data-ng-model="answer.text"
data-pid="answer.answerId"
data-field="{{'modal.data.answers[' + $index + '].text'}}"
id="modal-data-answer-{{$index}}"></textarea>
It's giving syntax errors no matter what I try. Does anyone have any idea what could be wrong? I want to pass in a field name with an array index value from inside an AngularJS ng-repeat.
app.directive('pagedownAdmin', function ($compile) {
var nextId = 0;
var markdownConverter = new Markdown.Converter();
var converter1 = Markdown.getSanitizingConverter();
converter1.hooks.chain("preBlockGamut", function (text, rbg) {
return text.replace(/^ {0,3}""" *\n((?:.*?\n)+?) {0,3}""" *$/gm, function (whole, inner) {
return "<blockquote>" + rbg(inner) + "</blockquote>\n";
});
});
return {
require: 'ngModel',
replace: true,
scope: {
field: '=field',
modal: '=modal',
pid: '=pid'
},
template: '<div class="pagedown-bootstrap-editor"></div>',
link: function (scope, element, attrs, ngModel) {
Later in my directive I have:
scope.$eval(attrs.field + "=" + rawContent);
scope.$apply();
However it does not appear to get to the point of doing the $eval before it gives the error.
Here's the syntax error:
Error: [$parse:syntax] http://errors.angularjs.org/1.2.3/$parse/syntax?p0='modal.data.answers%5B'&…7D%7D&p4='modal.data.answers%5B'%20%2B%20%24index%20%2B%20'%5D.text'%7D%7D
at Error (<anonymous>)
at http://127.0.0.1:81/Scripts/angular-v1.2.3/angular.min.js:6:449