【发布时间】:2018-08-01 17:19:19
【问题描述】:
无法使用指令在模板上绑定属性
我似乎无法使用指令在模板上绑定属性。任何帮助或建议都会很棒!
它给了我这个错误:
[$parse:syntax] 语法错误:令牌“{”在第 2 列的键无效 表达式 [{{$ctrl.CalendarOpen}}] 开始于 [{$ctrl.CalendarOpen}}]。
这是我的指令:
app.directive('datePickerDirective', [function () {
return {
restrict: 'AE',
scope: {
},
template: `
<input type="text" class="form-control"
uib-datepicker-popup="shortDate"
name="date" is-open="{{$ctrl.CalendarOpen}}"
ng-model="test" datepicker-options="dateOptions"
ng-required="true" close-text="Close" />`,
controller: function() {
var $ctrl = this;
$ctrl.CalendarOpen = true
},
controllerAs: '$ctrl',
}
}]);
【问题讨论】:
-
从
is-open属性中删除双花括号{{,即is-open="$ctrlCalendarOpen"。 -
@georgeawg 谢谢!它没有在 html 中显示 is-open="true" 很奇怪,但它正在工作。如果我添加一个 id="{{$ctrl.CalendarOpen}}",它不会给我那个错误。
标签: angularjs angularjs-directive angular-ui-bootstrap angular-ui-datepicker