Avery основная проблема.
В моем приложении Angual 1.x есть функция, которую я вызываю из моего шаблона:
searchesDTController as results
results.filterResults = function(filter = null) {}
Однако я также хочу вызвать ту же функцию в моем контроллере:
vm.filterResults();
Это даст мне:
ReferenceError: vm.filterResults is not defined
Я тоже пробовал:
filterResults();
this.filterResults();
Почему angular сообщает о функции, которая не была определена, когда она четко определена?
Вот мой код:
function searchesDTController(DTOptionsBuilder, DTColumnBuilder) {
var vm = this;
vm.dtInstance = {};
vm.search = search;
vm.oneAtATime = false; // for the collpase/expand accordion
vm.dtOptions = DTOptionsBuilder
.fromSource('/listings/filter.json?string=' + vm.search)
.withDataProp('data')
.withDOM('frtip')
.withOption('processing', true)
.withOption('bServerSide', true)
.withOption('sDom', 'lBfrtip')
.withPaginationType('full_numbers')
.withOption('order', [0, 'asc'])
.withDisplayLength(10);
vm.dtColumns = [
DTColumnBuilder.newColumn('Listings.id').withTitle('#').withOption('name', 'Listings.id').renderWith(function(data, type, res) {return res.id;}),
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable().withOption('searchable', false)
.renderWith(function(data) {
return '<a href="/listings/view/'+data.id+'"><button class="btn btn-success btn-xs">View</button></a>';
}),
];
vm.dtColumns[0].visible = false; // hide the id column - not needed
vm.filterResults("a-string"); //line 28
vm.filterResults = function(filter = null) { /* code */ }
Ошибка возникает в строке 28
Plunkr с фиксом
https://plnkr.co/edit/YXhEBDDbFzG05Bwe844w?p=preview