I get SyntaxError: Parse error
在我的指令行中,我想使用父指令方法中的“&”单向绑定
myApp.directive('datasourceDeleteBtn', [function() {
return {
restrict: 'E',
replace: true,
template: '<a href="#">✕</a>',
scope: {
datasourceIndex: '@',
removeParentDiv: '&'
},
link: link
};
function link(scope, element, attr) {
element.bind('click', function(event) {
event.preventDefault();
scope.deleteDatasource(scope.datasourceIndex);
});
// Notify parent directive
scope.deleteDatasource = function(datasource_index) {
// conditional stuff that happens not included
// {} required for passing values to "&" parent scope method
scope.removeParentDiv({datasource_index});
};
}
}]);
HTML
<parent-div ng-repeat> // this is just a mockup not literal
<datasource-delete-btn datasource-index="{{$index}}" remove-parent-div="removeParentDiv()"></datasource-delete-btn>
</parent-div>
传递removeParentDiv的ng-repeat的父div
// parentDiv directive has this
scope.datasources = [];
scope.removeDatasourcePicker = function(index) {
scope.datasources.splice(index, 1); // ie take it out
};
看来问题是 Jasmine 不喜欢 { }。删除括号会导致测试通过(由于 & 需要 {},因此会出现典型错误)。